diff --git a/src/tests/number.test.ts b/src/tests/number.test.ts index ab82a75a..3d191032 100644 --- a/src/tests/number.test.ts +++ b/src/tests/number.test.ts @@ -31,6 +31,11 @@ describe('getCurrencyHelpers', () => { expect(toUIString(value)).toBe('$1,234'); }); + it('Should correctly format single digit cent amounts', () => { + const value = 7n; + expect(toUIString(value)).toBe('$0.07'); + }); + it.each([ [12345n, '$123.45'], [-12345n, '-$123.45'], diff --git a/src/utils/numbers.ts b/src/utils/numbers.ts index 4d2f52dc..4fa31b50 100644 --- a/src/utils/numbers.ts +++ b/src/utils/numbers.ts @@ -147,7 +147,7 @@ export const getCurrencyHelpers = ({ if (typeof value === 'bigint') { const sign = value < 0n && signed ? '-' : ''; const integer = `${value / decimalMultiplierN}`; - const fraction = `${value}`.slice(-decimalDigits); + const fraction = `${value}`.slice(-decimalDigits).padStart(decimalDigits, '0'); return ( sign + normalizeToMaxLength(