Skip to content

Commit

Permalink
Merge pull request #1504 from bcgov/fix/daniel-round-summary-numbers-…
Browse files Browse the repository at this point in the history
…1462

fix: Round non-currency numbers in Summary Table
  • Loading branch information
dhaselhan authored Dec 20, 2024
2 parents 7314769 + eca1dea commit dfb5501
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 dfb5501

Please sign in to comment.