The toLocaleString() method is your go-to for formatting numbers, dates, and times based on regional settings 🌍.
Here's how it makes your app more user-friendly:
Basic Usage:
1. Format numbers based on the current locale:
> 1234567.89.toLocaleString() ➡️ "1,234,567.89" (varies by region)
2. Number & Currency Formatting:
✨ Support for locales like German, Japanese, or even Bangladeshi Taka!
> number.toLocaleString('de-DE') ➡️ "1.234.567,89"
> number.toLocaleString('bn-BD', { style: 'currency', currency: 'BDT' })➡️ "৳১,২৩,৪৫,৬৭৮.৮৯"
3. Percentage Formatting:
Easily display percentages:
> 0.1234.toLocaleString('en-US', { style: 'percent' }) ➡️ "12%"
4. Date & Time Formatting:
Present dates and times in any locale:
> new Date().toLocaleString('en-GB') ➡️ "Friday, 30 August 2024 at 11:24"
Make your apps culturally adaptable! 🌎
please log in to comment.