Skip to content

Commit

Permalink
fix: Round non-currency numbers in Summary Table
Browse files Browse the repository at this point in the history
* Update number formatter to take max decimals
* Set max decimals to 0 on Summary Page
  • Loading branch information
dhaselhan committed Dec 18, 2024
1 parent cb5f7aa commit 0bbea98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions frontend/src/utils/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ const SummaryTable = ({
{row.format && colIndex !== 0
? rowFormatters[row.format](
row[column.id],
useParenthesis
useParenthesis,
0
)
: row[column.id]}
</span>
Expand Down

0 comments on commit 0bbea98

Please sign in to comment.