- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Number Formatting
JavaScript Numbers & Math
JavaScript Number Formatting
toLocaleStringformats numbers as currency, percentages and grouped digits.
toFixed handles decimal places but nothing else.
For anything a person will read, this is the better tool.
Example
Example
javascript
const value = 1234567.891;
console.log(value.toLocaleString("en-GB"));The digits are grouped and the decimals rounded.
Formatting Options
The first argument is a locale, such as en-GB or en-IN.
The second is an options object.
style can be decimal, currency, percent or unit.
