toLocaleString() not supported in all browsers?(并非所有浏览器都支持 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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:并非所有浏览器都支持 toLocaleString()?


- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01