Number.prototype.toLocaleString()和Intl.NumberFormat.prototype.format之间是什么关系? [英] What is the relation between Number.prototype.toLocaleString() and Intl.NumberFormat.prototype.format?

查看:113
本文介绍了Number.prototype.toLocaleString()和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?

推荐答案

从MDN文档获取

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 its NumberFormat.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆