Hello i have a question about:
Number.prototype.toLocaleString()
Trouble is that when we use "toLocaleString()" method it will not show latest maximumFractionDigits value if there was "0".
var i = 50456.40345345;
i.toLocaleString('en-US', {maximumFractionDigits: 2})
// It will return "50,456.4".
// I want to see "50,456.40".
How can i do that?
Hello i have a question about:
Number.prototype.toLocaleString()
Trouble is that when we use "toLocaleString()" method it will not show latest maximumFractionDigits value if there was "0".
var i = 50456.40345345;
i.toLocaleString('en-US', {maximumFractionDigits: 2})
// It will return "50,456.4".
// I want to see "50,456.40".
How can i do that?
Share Improve this question asked May 6, 2015 at 16:29 ValeeValee 811 silver badge6 bronze badges 2-
1
How about using
minimumFractionDigits
too? – Teemu Commented May 6, 2015 at 16:31 - Thanks Teemu, i forgot. – Valee Commented May 6, 2015 at 16:33
1 Answer
Reset to default 8Use minimumFractionDigits
:
var i = 50456.40345345;
i = i.toLocaleString('en-US', {maximumFractionDigits: 2, minimumFractionDigits: 2});
document.write(i);
Although you are specifying the maximumFractionDigits
, the numbers don't necessarily have 2 fraction digits, so that's why you need to specify minimumFractionDigits
.