Skip to content

Commit

Permalink
use engineering notation for very large numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed Dec 18, 2024
1 parent e040682 commit abd4d7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils/helpers/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ describe('Test helpers', () => {
'0.00000012345'
);
});

// Very large numbers
test('should return "100.00E18" for input 1e20', () => {
expect(prettifyNumber(1e20)).toEqual('100.00E18');
});
});
});

Expand Down
4 changes: 4 additions & 0 deletions src/utils/helpers/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ const getIntlOptions = (value: SafeDecimal, options: PrettifyNumberOptions) => {
if (options.abbreviate && value.gte(1_000_000)) {
intlOptions.notation = 'compact';
}
// When ludicrous numbers, use 1E16 notation
if (value.gt(1e17)) {
intlOptions.notation = 'engineering';
}
return intlOptions;
};

Expand Down

0 comments on commit abd4d7d

Please sign in to comment.