What is the relation between Number.prototype.toLocaleString() and Intl.NumberFormat.prototype.format?

那年仲夏 提交于 2019-12-11 00:32:29

问题


We are trying to use localization support in our application and looking at the toLocaleString(). We also had a look at Intl.NumberFormat and its format method.

Do they have any relation? Which one is better to use?


回答1:


From MDN docs for Number.prototype.toLocaleString():

When formatting large numbers of numbers, it is better to create a NumberFormat object and use the function provided by its NumberFormat.format property.

In most cases you can use Number.prototype.toLocaleString(). It's simpler to use, because it allows you to format a number using one function call. Intl.NumberFormat is useful only when you want to format a large amount of numbers.



来源:https://stackoverflow.com/questions/39751736/what-is-the-relation-between-number-prototype-tolocalestring-and-intl-numberfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!