Skip to content

Commit

Permalink
fix: consider thousandSeparated (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
Holybasil authored May 21, 2024
1 parent 9452bbd commit 93233b4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const commafy = (value: string | number | undefined, decimals: number = 2
try {
return numbro(value).format({
thousandSeparated: true,
optionalMantissa: false,
optionalMantissa: true,
mantissa: decimals,
})
} catch (err) {
Expand Down Expand Up @@ -67,7 +67,8 @@ export const toPrecision = (amount, precise = 8) => {
}
const withPrecision = commafy(amount, significantDecimals)
// Remove trailing zeros after decimal point
return parseFloat(withPrecision).toString()
const withoutTrailingZero = withPrecision.replace(/(\.\d*?)0+$/, "$1").replace(/(\.\d+?)0+$/, "$10")
return withoutTrailingZero
}

export function sanitizeNumericalString(numStr: string) {
Expand Down

0 comments on commit 93233b4

Please sign in to comment.