I want to format numbers using JavaScript.
For example:
10 => 10.00
100 => 100.00
1000 => 1,000.00
10000 => 10,000.00
100000 => 100,000.00
I want to format numbers using JavaScript.
For example:
10 => 10.00
100 => 100.00
1000 => 1,000.00
10000 => 10,000.00
100000 => 100,000.00
If you're using jQuery, you could use the format or number format plugins.
If you want to use built-in code, you can use
toLocaleString()
withminimumFractionDigits
, although browser compatibility for the extended options ontoLocaleString()
is limited.If you're using Node.js, you will need to
npm install
theintl
package.On browsers that support the ECMAScript® 2016 Internationalization API Specification (ECMA-402), you can use an
Intl.NumberFormat
instance:This is an article about your problem. Adding a thousands-seperator is not built in to JavaScript, so you'll have to write your own function like this (example taken from the linked page):