tolocalestring javascript currency fixing 2 decimal places 1

tolocalestring javascript currency fixing 2 decimal places

var num = 2046430;
num.toLocaleString(undefined, {minimumFractionDigits: 2}) // 2,046,430.00

Here is what the above code is Doing:
1. We’re using the toLocaleString() method to convert the number to a string.
2. We’re passing in undefined as the first argument to toLocaleString() to use the default locale.
3. We’re passing in an object as the second argument to toLocaleString() to specify the minimum number of fraction digits to use.
4. We’re using the minimumFractionDigits property to specify the minimum number of fraction digits to use.

Similar Posts