Files
zellyy-finance/src/utils/formatters.ts
gpt-engineer-app[bot] a0866492ac Fix NaN percentage display
Ensure percentage displays 0 instead of NaN when budget target is zero.
2025-03-15 23:11:27 +00:00

15 lines
441 B
TypeScript

export const formatCurrency = (amount: number): string => {
return new Intl.NumberFormat('ko-KR', {
style: 'currency',
currency: 'KRW',
maximumFractionDigits: 0
}).format(amount);
};
export const calculatePercentage = (spent: number, target: number): number => {
// 타겟이 0이면 0%를 반환하도록 수정
if (target === 0 || isNaN(target)) return 0;
return Math.min(Math.round(spent / target * 100), 100);
};