Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/tests/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion src/utils/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading