27 lines
782 B
TypeScript
27 lines
782 B
TypeScript
/**
|
|
* Number and currency formatting utilities.
|
|
*/
|
|
|
|
/** Formats a P/E ratio — e.g. 22.5 → "22.5x", null → "—" */
|
|
export function fmtPE(v: number | null | undefined): string {
|
|
return v != null ? v + 'x' : '—';
|
|
}
|
|
|
|
/** Full currency format — e.g. 1234.5 → "$1,234.50" */
|
|
export function fmt(n: number | null | undefined): string {
|
|
return n != null
|
|
? new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(n)
|
|
: '—';
|
|
}
|
|
|
|
/** Compact currency format (no cents) — e.g. 1234.5 → "$1,235" */
|
|
export function fmtShort(n: number | null | undefined): string {
|
|
return n != null
|
|
? new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency: 'USD',
|
|
maximumFractionDigits: 0,
|
|
}).format(n)
|
|
: '—';
|
|
}
|