最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - toLocaleString() don't show zero - Stack Overflow

programmeradmin7浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 8

Use 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.

发布评论

评论列表(0)

  1. 暂无评论