diff --git a/core/base/__tests__/amount.ts b/core/base/__tests__/amount.ts index 839328894..f95f966d5 100644 --- a/core/base/__tests__/amount.ts +++ b/core/base/__tests__/amount.ts @@ -79,7 +79,7 @@ describe("Amount Tests", function () { [{ amount: "1", decimals: 18 }, 20, "0.00000000000000000100"], [{ amount: "5020", decimals: 2 }, 0, "50.2"], [{ amount: "5020", decimals: 2 }, 4, "50.2000"], - [{ amount: "5020", decimals: 2 }, undefined, "50.20"], + [{ amount: "5020", decimals: 2 }, undefined, "50.2"], [{ amount: "1", decimals: 0 }, 0, "1"], ]; diff --git a/core/base/src/utils/amount.ts b/core/base/src/utils/amount.ts index 1a1d0b72b..65a57a759 100644 --- a/core/base/src/utils/amount.ts +++ b/core/base/src/utils/amount.ts @@ -157,6 +157,10 @@ export function display(amount: Amount, precision?: number): string { partial = partial.substring(0, partial.length - 1); } partial = partial.padEnd(precision, "0"); + } else { + // If no specific precision is given, just trim trailing zeroes + // and return all significant digits. + partial = partial.replace(/0+$/, ''); } return partial.length > 0 ? `${whole}.${partial}` : whole;