并非所有浏览器都支持 toLocaleString()? [英] toLocaleString() not supported in all browsers?

查看:31
本文介绍了并非所有浏览器都支持 toLocaleString()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的功能:

Chrome、Firefox、IE:

Chrome, Firefox, IE:

Number(1000000).toLocaleString()
"1 000 000" // in french system, the space is the separator instead of the comma

Opera,傲游:

Number(1000000).toLocaleString()
"1000000"

为什么 Opera 和 Maxthon 不能格式化?他们支持这种方法,但没有以正确的方式执行?

why Opera and Maxthon cant format it? they support this method but dont execute it in the right way?

是否有任何 toLocaleString() 替换?

推荐答案

语言规范 定义非常开放:

生成一个字符串值,该值表示根据宿主环境当前语言环境的约定格式化的数字值.此函数依赖于实现,允许但不鼓励它返回与 toString 相同的内容.

15.7.4.3 Number.prototype.toLocaleString()

Produces a String value that represents this Number value formatted according to the conventions of the host environment’s current locale. This function is implementation-dependent, and it is permissible, but not encouraged, for it to return the same thing as toString.

允许不同的浏览器以不同的方式实现它,并且可以根据用户选择的语言环境以不同的方式实现它.

Different browsers are allowed to implement it differently, and can implement it differently based on the locale chosen by the user.

这篇关于并非所有浏览器都支持 toLocaleString()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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