formatCurrency

Formatea un número como moneda usando Intl.NumberFormat.

#intl #formatting #currency #utility
export const formatCurrency = (
value: number,
currency = 'USD',
locale = 'en-US',
) =>
new Intl.NumberFormat(locale, {
style: 'currency',
currency,
}).format(value);
// Usage
formatCurrency(1234.56); // "$1,234.56"
formatCurrency(1234.56, 'EUR', 'de'); // "1.234,56 €"
formatCurrency(1234.56, 'JPY', 'ja'); // "¥1,235"

Comparte este snippet

Comentarios