問題描述
我有這個簡單的功能:
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()?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!