From bd883edf8ac60031ecb1d21d211166b3c829b2c0 Mon Sep 17 00:00:00 2001 From: Oumar Fall Date: Thu, 17 Oct 2024 15:33:43 +0200 Subject: [PATCH] fix(morpho-ts): fix formatter --- packages/morpho-ts/src/format/format/format.ts | 5 ++++- packages/morpho-ts/test/format.test.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/morpho-ts/src/format/format/format.ts b/packages/morpho-ts/src/format/format/format.ts index 91024b32..758ac82b 100644 --- a/packages/morpho-ts/src/format/format/format.ts +++ b/packages/morpho-ts/src/format/format/format.ts @@ -126,7 +126,10 @@ const _formatShort = ( if (formatOptions.smallValuesWithCommas) { return _formatCommas(bi, decimals, formatOptions); } - return _applyOptions(stringValue.insert(-decimals, ".", "0"), formatOptions); + return _applyOptions( + decimals ? stringValue.insert(-decimals, ".", "0") : stringValue, + formatOptions, + ); }; const _formatCommas = ( diff --git a/packages/morpho-ts/test/format.test.ts b/packages/morpho-ts/test/format.test.ts index 79f5f700..85e70563 100644 --- a/packages/morpho-ts/test/format.test.ts +++ b/packages/morpho-ts/test/format.test.ts @@ -200,6 +200,10 @@ describe("format", () => { describe("short", () => { describe("should properly format number in short format", () => { + test("with small integers", () => { + expect(format.short.of(123)).toEqual("123"); + }); + test("without option", () => { expect(format.short.of(number)).toEqual("12.3456789k"); }); @@ -255,6 +259,10 @@ describe("format", () => { }); describe("should properly format bigint in short format", () => { + test("with small integers", () => { + expect(format.short.of(123n, 0)).toEqual("123"); + }); + test("without option", () => { expect(format.short.of(bigint, decimals)).toEqual("12.3456789k"); });