From 0bbea98fb22324adf556f2147a0896bf3e023382 Mon Sep 17 00:00:00 2001 From: Daniel Haselhan Date: Wed, 18 Dec 2024 14:44:45 -0800 Subject: [PATCH] fix: Round non-currency numbers in Summary Table * Update number formatter to take max decimals * Set max decimals to 0 on Summary Page --- frontend/src/utils/formatters.js | 9 +++++++-- .../views/ComplianceReports/components/SummaryTable.jsx | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/src/utils/formatters.js b/frontend/src/utils/formatters.js index 78ed0e0e6..ebcdaeef6 100644 --- a/frontend/src/utils/formatters.js +++ b/frontend/src/utils/formatters.js @@ -7,9 +7,14 @@ import { ROLES_BADGE_SIZE } from '@/constants/common' * @param {Object|number|string|null} params - The input parameter which can be an object with a `value` property, a number, or a string. * @param {number|string} [params.value] - The value to be formatted, if params is an object. * @param {boolean} [useParentheses=false] - Whether to use parentheses for negative numbers. + * @param maxDecimals the max number of decimals to return * @returns {string} - The formatted number as a string, or the original value if it cannot be parsed as a number. */ -export const numberFormatter = (params, useParentheses = false) => { +export const numberFormatter = ( + params, + useParentheses = false, + maxDecimals = 10 +) => { if (params == null || (typeof params === 'object' && params.value == null)) return '' @@ -21,7 +26,7 @@ export const numberFormatter = (params, useParentheses = false) => { const absValue = Math.abs(parsedValue) const formattedValue = absValue.toLocaleString(undefined, { minimumFractionDigits: 0, - maximumFractionDigits: 10 + maximumFractionDigits: maxDecimals }) if (parsedValue < 0) { diff --git a/frontend/src/views/ComplianceReports/components/SummaryTable.jsx b/frontend/src/views/ComplianceReports/components/SummaryTable.jsx index 0077e5bde..952b918ee 100644 --- a/frontend/src/views/ComplianceReports/components/SummaryTable.jsx +++ b/frontend/src/views/ComplianceReports/components/SummaryTable.jsx @@ -194,7 +194,8 @@ const SummaryTable = ({ {row.format && colIndex !== 0 ? rowFormatters[row.format]( row[column.id], - useParenthesis + useParenthesis, + 0 ) : row[column.id]}