Skip to content

Commit

Permalink
Merge pull request #131 from morpho-org/fix/format-short-small-integers
Browse files Browse the repository at this point in the history
fix(morpho-ts): fix formatter
  • Loading branch information
oumar-fall authored Oct 17, 2024
2 parents 242d209 + bd883ed commit cb6a45f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/morpho-ts/src/format/format/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
8 changes: 8 additions & 0 deletions packages/morpho-ts/test/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down Expand Up @@ -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");
});
Expand Down

0 comments on commit cb6a45f

Please sign in to comment.