/** * Format price - shows decimals only if needed * Uses space as thousands separator (common in Paraguay) * Examples: * 45000 PYG -> "45 000 PYG" (no decimals) * 41.44 PYG -> "41,44 PYG" (with decimals) */ export function formatPrice(price: number, currency: string = 'PYG'): string { const hasDecimals = price % 1 !== 0; // Format the integer and decimal parts separately const intPart = Math.floor(Math.abs(price)); const decPart = Math.abs(price) - intPart; // Format integer part with space as thousands separator const intFormatted = intPart.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' '); // Build final string let result = price < 0 ? '-' : ''; result += intFormatted; // Add decimals only if present if (hasDecimals) { const decStr = decPart.toFixed(2).substring(2); // Get just the decimal digits result += ',' + decStr; } return `${result} ${currency}`; } /** * Format currency amount (alias for formatPrice for backward compatibility) */ export function formatCurrency(amount: number, currency: string = 'PYG'): string { return formatPrice(amount, currency); }