From 654310fa507d35738d811b1bdad19c3f442bc1d1 Mon Sep 17 00:00:00 2001 From: youngkidwarrior Date: Thu, 1 Aug 2024 18:24:08 -0700 Subject: [PATCH] use toFixed to round formatted amount --- packages/app/utils/formatAmount.test.ts | 4 ++-- packages/app/utils/formatAmount.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/app/utils/formatAmount.test.ts b/packages/app/utils/formatAmount.test.ts index 368863e18..1094c66d9 100644 --- a/packages/app/utils/formatAmount.test.ts +++ b/packages/app/utils/formatAmount.test.ts @@ -55,7 +55,7 @@ describe('formatAmount', () => { }) it('should format to locale string', () => { - expect(formatAmount(123.4567, 4, 2)).toBe('123.45') + expect(formatAmount(123.4567, 4, 2)).toBe('123.46') }) it('should not round string numbers', () => { @@ -75,7 +75,7 @@ describe('maxIntegers handling', () => { }) describe('maxDecimals handling', () => { it('should truncate decimals that exceed maxDecimals', () => { - expect(formatAmount(123.45678, 5, 2)).toBe('123.45') // input has 5 decimals, but only 2 are expected in output + expect(formatAmount(123.45678, 5, 2)).toBe('123.46') // input has 5 decimals, but only 2 are expected in output }) it('should format to maxDecimals even if input has fewer decimals', () => { diff --git a/packages/app/utils/formatAmount.ts b/packages/app/utils/formatAmount.ts index f5efd6029..b65378ff4 100644 --- a/packages/app/utils/formatAmount.ts +++ b/packages/app/utils/formatAmount.ts @@ -119,7 +119,7 @@ export default function formatAmount( return ( (lessThanMin ? '>' : '') + - Number(floor(Number(amount), maxDecimals)).toLocaleString(undefined, { + Number(Number(amount).toFixed(maxDecimals)).toLocaleString(undefined, { useGrouping: true, minimumFractionDigits: (decimals || 0) < maxDecimals ? decimals : maxDecimals, maximumFractionDigits: maxDecimals,