How do you format numbers and currency for a locale using Intl.NumberFormat?
Short answer
Intl.NumberFormat handles locale-aware digit grouping, decimal separators, and currency symbols automatically, avoiding manual and error-prone string manipulation.
Advertisement
AModel answer
Intl.NumberFormat handles locale-aware digit grouping, decimal separators, and currency symbols automatically, avoiding manual and error-prone string manipulation.
const price = new Intl.NumberFormat('de-DE', {
style: 'currency', currency: 'EUR'
}).format(1234.5);
console.log(price); // '1.234,50 €'Real-world example
Displaying product prices correctly formatted for a user's detected region.
Likely follow-ups
- How would you format a large number with abbreviations like '1.2K'?
Related topics