Files
multiverse/jumpa-iam/lib/currency.ts
T

15 lines
578 B
TypeScript

export type Currency = 'Rp' | 'USD' | 'Crypto';
export function formatCurrency(amountUSD: number, currency: Currency): string {
if (currency === 'USD') {
return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amountUSD);
} else if (currency === 'Rp') {
// 1 USD = 16000 Rp (Simulation)
return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR' }).format(amountUSD * 16000);
} else if (currency === 'Crypto') {
// 1 USD = 1 USDT
return `${amountUSD.toFixed(2)} USDT`;
}
return amountUSD.toString();
}