Is there function to convert a value to number format in JavaScript?
Ex: 10006.1056 to 10,006.16
Yes there is.
Best way is to create a NumberFormat you can re-use for your locale.
For example 'en-US' (USA) or 'en-IN' (India).
To set the maximum precision digits, use the option maximumFractionDigits.
If you always want to use 2 precision digits for example: 1 must be 1.00 use minimumFractionDigits too.
var number = 10006.1056;
var nf = new Intl.NumberFormat('en-US', {
maximumFractionDigits:2,
minimumFractionDigits:2
});
var formattedNumber = nf.format(number); // Will output 10,006.10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With