From ddf50de66f339fc41b1c88f3630305d956e8eacd Mon Sep 17 00:00:00 2001 From: Maria Katrin Bonde Date: Fri, 10 Jan 2025 10:23:54 +0100 Subject: [PATCH] rounding two decimals --- .../components/Forecast/TransformWeekDataToMonth.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/Forecast/TransformWeekDataToMonth.ts b/frontend/src/components/Forecast/TransformWeekDataToMonth.ts index bbae5e07..fb44e651 100644 --- a/frontend/src/components/Forecast/TransformWeekDataToMonth.ts +++ b/frontend/src/components/Forecast/TransformWeekDataToMonth.ts @@ -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 } = {}; @@ -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; } @@ -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) {