feat: rebuild fiscal clone architecture and harden coolify deployment
This commit is contained in:
29
frontend/lib/format.ts
Normal file
29
frontend/lib/format.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export function asNumber(value: string | number | null | undefined) {
|
||||
if (value === null || value === undefined) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const parsed = typeof value === 'number' ? value : Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
}
|
||||
|
||||
export function formatCurrency(value: string | number | null | undefined) {
|
||||
return new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'USD',
|
||||
maximumFractionDigits: 2
|
||||
}).format(asNumber(value));
|
||||
}
|
||||
|
||||
export function formatPercent(value: string | number | null | undefined) {
|
||||
return `${asNumber(value).toFixed(2)}%`;
|
||||
}
|
||||
|
||||
export function formatCompactCurrency(value: string | number | null | undefined) {
|
||||
return new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'USD',
|
||||
notation: 'compact',
|
||||
maximumFractionDigits: 2
|
||||
}).format(asNumber(value));
|
||||
}
|
||||
Reference in New Issue
Block a user