Is there a way to get number.toLocaleString()
with 4 digits after the comma?
Example:
var number = 49.9712; document.getElementById('id').innerText = number.toLocaleString();
Result: 49,9712
But now it always returns number with 2 digits after comma: 49,97
The toLocaleString() method returns a Date object as a string, using locale settings. The default language depends on the locale setup on your computer.
The toFixed() method rounds the string to a specified number of decimals.
The toLocaleString() method will round the resulting value if necessary. The toLocaleString() method does not change the value of the original number.
You may use second argument to provide some options. In your case, with default locale:
number.toLocaleString(undefined, { minimumFractionDigits: 4 })
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