fix(format): divide by 1e9 in formatLongNumber billions branch
The billions branch of formatLongNumber divided by 1000000 while appending the 'b' suffix, so values >= 1e9 rendered about 1000x too large (1000000000 became '1000.0b' instead of '1.0b'). Divide by 1000000000 to match the 'b' unit, consistent with the sibling formatLongCurrency. Add regression tests for the billions branch.
This commit is contained in:
2 files changed
+3
-1
No files matched your search
@@ -27,6 +27,8 @@ test('formatNumber', () => {
|
||||
});
|
||||
|
||||
test('formatLongNumber', () => {
|
||||
expect(format.formatLongNumber(1000000000)).toBe('1.0b');
|
||||
expect(format.formatLongNumber(2500000000)).toBe('2.5b');
|
||||
expect(format.formatLongNumber(1200000)).toBe('1.2m');
|
||||
expect(format.formatLongNumber(575000)).toBe('575k');
|
||||
expect(format.formatLongNumber(10500)).toBe('10.5k');
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ export function formatLongNumber(value: number) {
|
||||
const n = Number(value);
|
||||
|
||||
if (n >= 1000000000) {
|
||||
return `${(n / 1000000).toFixed(1)}b`;
|
||||
return `${(n / 1000000000).toFixed(1)}b`;
|
||||
}
|
||||
if (n >= 1000000) {
|
||||
return `${(n / 1000000).toFixed(1)}m`;
|
||||
|
||||
Reference in new issue
Block a user