Formats a number according to a locale.
根据语言环境格式化数字。
By default the locale is US english:
默认情况下,语言环境为美式英语:
new Number(21.2).toLocaleString() //21.2
We can pass the locale as the first parameter:
我们可以将语言环境作为第一个参数传递:
new Number(21.2).toLocaleString('it') //21,2
This is eastern arabic
这是阿拉伯东部
new Number(21.2).toLocaleString('ar-EG') //٢١٫٢
There are a number of options you can add, and I suggest to look at the MDN page to know more.
您可以添加许多选项,建议您查看MDN页面以了解更多信息。
翻译自: https://flaviocopes.com/javascript-number-tolocalestring/