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

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

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Sep 28, 2016 at 15:55 Michał Perłakowski 92.6k30 gold badges163 silver badges186 bronze badges asked Sep 28, 2016 at 15:26 TypeScripterTypeScripter 9092 gold badges11 silver badges23 bronze badges 1
  • Thank you for replying back. yes, I read both of them and I can see that via both ways I can achieve almost similar tasks. However, I am still trying to find which one is better than other (in other words, which one I should prefer and why). I also saw a minimal reference of Intl namespace in localeString doc, but didn't quite grasp how they are related. So, looking for some real world examples. – TypeScripter Commented Sep 28, 2016 at 15:44
Add a ment  | 

1 Answer 1

Reset to default 17

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

Performance:

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论