From 90785c2a148a9d8a589762a8337f12d53d8f2bfd Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 3 Jul 2026 17:17:47 +0200 Subject: [PATCH] Refactor rounding logic --- .../treemap-chart/treemap-chart.component.ts | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts b/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts index 36ea0023a..2a04ba6ba 100644 --- a/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts +++ b/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts @@ -30,7 +30,7 @@ import { Chart, Tooltip } from 'chart.js'; import { TreemapController, TreemapElement } from 'chartjs-chart-treemap'; import { isUUID } from 'class-validator'; import { differenceInDays, max } from 'date-fns'; -import { orderBy } from 'lodash'; +import { orderBy, round } from 'lodash'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import OpenColor from 'open-color'; @@ -221,9 +221,10 @@ export class GfTreemapChartComponent ) }).toNumber(); - // Round to 2 decimal places - annualizedNetPerformancePercent = - Math.round(annualizedNetPerformancePercent * 100) / 100; + annualizedNetPerformancePercent = round( + annualizedNetPerformancePercent, + 2 + ); const { backgroundColor } = this.getColor({ annualizedNetPerformancePercent, @@ -252,9 +253,10 @@ export class GfTreemapChartComponent ) }).toNumber(); - // Round to 2 decimal places - annualizedNetPerformancePercent = - Math.round(annualizedNetPerformancePercent * 100) / 100; + annualizedNetPerformancePercent = round( + annualizedNetPerformancePercent, + 2 + ); const { fontColor } = this.getColor({ annualizedNetPerformancePercent, @@ -267,11 +269,10 @@ export class GfTreemapChartComponent display: true, font: [{ size: 16 }, { lineHeight: 1.5, size: 14 }], formatter: ({ raw }: GfTreemapScriptableContext) => { - // Round to 4 decimal places - let netPerformancePercentWithCurrencyEffect = - Math.round( - raw._data.netPerformancePercentWithCurrencyEffect * 10000 - ) / 10000; + let netPerformancePercentWithCurrencyEffect = round( + raw._data.netPerformancePercentWithCurrencyEffect, + 4 + ); if (Math.abs(netPerformancePercentWithCurrencyEffect) === 0) { netPerformancePercentWithCurrencyEffect = Math.abs(