Skip to content

Commit

Permalink
rounding two decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaBonde committed Jan 10, 2025
1 parent d36e943 commit ddf50de
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions frontend/src/components/Forecast/TransformWeekDataToMonth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
import { getMonthOfWeek, weekToWeekType } from "./WeekToMonthConverter";
import { add } from "lodash";

function round2Decimals(num: number) {
return Math.round(num * 100) / 100;
}
function transformToMonthlyData(weeklyData: BookedHoursPerWeek[]) {
const monthlyData: { [key: string]: BookedHoursPerMonth } = {};

Expand Down Expand Up @@ -39,7 +42,9 @@ function transformToMonthlyData(weeklyData: BookedHoursPerWeek[]) {
for (const key of Object.keys(
bookingModel,
) as (keyof WeeklyBookingReadModel)[]) {
distributedModel[key] = bookingModel[key] * distribution;
distributedModel[key] = round2Decimals(
bookingModel[key] * distribution,
);
}
return distributedModel;
}
Expand Down Expand Up @@ -132,9 +137,11 @@ function transformDetailedBookingToMonthlyData(
monthDistribution.secondMonth
}`
: null;
const primaryDistribution = monthDistribution.distribution / 100;
const primaryDistribution = round2Decimals(
monthDistribution.distribution / 100,
);
const secondaryDistribution = secondaryMonthKey
? (100 - monthDistribution.distribution) / 100
? round2Decimals((100 - monthDistribution.distribution) / 100)
: 0;
addToMonthlyHours(primaryMonthKey, hours, primaryDistribution);
if (secondaryMonthKey) {
Expand Down

0 comments on commit ddf50de

Please sign in to comment.