Number.prototype.toLocaleString()和Intl.NumberFormat.prototype.format之间是什么关系? [英] What is the relation between Number.prototype.toLocaleString() and Intl.NumberFormat.prototype.format?
问题描述
我们正在尝试在应用程序中使用本地化支持,并查看toLocaleString()
.我们还研究了Intl.NumberFormat
及其格式方法.
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?
推荐答案
From MDN docs for Number.prototype.toLocaleString()
:
格式化大量数字时,最好创建一个
NumberFormat
对象并使用其NumberFormat.format
属性提供的功能.
When formatting large numbers of numbers, it is better to create a
NumberFormat
object and use the function provided by itsNumberFormat.format
property.
在大多数情况下,您可以使用Number.prototype.toLocaleString()
.它更易于使用,因为它允许您使用一个函数调用来格式化数字. Intl.NumberFormat
仅在您要格式化大量数字时才有用.
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.
这篇关于Number.prototype.toLocaleString()和Intl.NumberFormat.prototype.format之间是什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!