Add K/M/B scale toggles for financial displays
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import { formatScaledNumber } from './format';
|
||||
import { formatCurrencyByScale, formatScaledNumber } from './format';
|
||||
|
||||
describe('formatScaledNumber', () => {
|
||||
it('keeps values below one thousand unscaled', () => {
|
||||
@@ -27,3 +27,21 @@ describe('formatScaledNumber', () => {
|
||||
expect(formatScaledNumber(999_950)).toBe('1M');
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatCurrencyByScale', () => {
|
||||
it('formats values in thousands', () => {
|
||||
expect(formatCurrencyByScale(12_345, 'thousands')).toBe('$12.3K');
|
||||
});
|
||||
|
||||
it('formats values in millions', () => {
|
||||
expect(formatCurrencyByScale(12_345_678, 'millions')).toBe('$12.3M');
|
||||
});
|
||||
|
||||
it('formats values in billions', () => {
|
||||
expect(formatCurrencyByScale(12_345_678_901, 'billions')).toBe('$12.3B');
|
||||
});
|
||||
|
||||
it('keeps sign for negative values', () => {
|
||||
expect(formatCurrencyByScale(-2_500_000, 'millions')).toBe('-$2.5M');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user