Add K/M/B scale toggles for financial displays

This commit is contained in:
2026-03-01 19:23:45 -05:00
parent 209b650658
commit b8309c9969
5 changed files with 519 additions and 88 deletions

View File

@@ -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');
});
});