diff --git a/src/utils.ts b/src/utils.ts index c772036..aaea81a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -17,8 +17,10 @@ export function tryParseBigInt(value: string | number): bigint | null { } export function formatNumber(value: bigint, decimals: number): string { + if (value === 0n) { + return '0'; + } const numberString = value.toString(); - if (numberString.length <= decimals) { return `0.${numberString.padStart(decimals, '0')}`; } diff --git a/test/utils.test.ts b/test/utils.test.ts index c9e02a6..b1a6fc0 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -15,6 +15,5 @@ describe('Utils functions tests', () => { expect(formatNumber(BigInt(123), 5)).toEqual('0.00123'); expect(formatNumber(123000n, 2)).toEqual("1230"); expect(formatNumber(BigInt(0), 5)).toEqual('0'); - }) })