This method converts a number into a text string according to the specific locale. This includes number formatting settings and other aspects such as thousands separators and decimals. It is useful for presenting numbers in a format that is familiar to the user based on their geographic location or preferred language.
const number = 1234567.89;
console.log(number.toLocaleString('en-US'));
// "1,234,567.89"
console.log(number.toLocaleString('de-DE'));
// "1.234.567,89"
const number = 1234567.89;
const options = { style: 'currency', currency: 'USD' };
console.log(number.toLocaleString('en-US', options));
// "$1,234,567.89"
✨ Frontend Mentor - @mendezpvi
✨ iCodeThis - @mendezpvi