<i id='5mp7y'><tr id='5mp7y'><dt id='5mp7y'><q id='5mp7y'><span id='5mp7y'><b id='5mp7y'><form id='5mp7y'><ins id='5mp7y'></ins><ul id='5mp7y'></ul><sub id='5mp7y'></sub></form><legend id='5mp7y'></legend><bdo id='5mp7y'><pre id='5mp7y'><center id='5mp7y'></center></pre></bdo></b><th id='5mp7y'></th></span></q></dt></tr></i><div id='5mp7y'><tfoot id='5mp7y'></tfoot><dl id='5mp7y'><fieldset id='5mp7y'></fieldset></dl></div>
  • <small id='5mp7y'></small><noframes id='5mp7y'>

  • <legend id='5mp7y'><style id='5mp7y'><dir id='5mp7y'><q id='5mp7y'></q></dir></style></legend>

          <bdo id='5mp7y'></bdo><ul id='5mp7y'></ul>
        <tfoot id='5mp7y'></tfoot>

      1. Number().toLocaleString() 在不同的浏览器中有不同的格

        时间:2023-05-30

        <tfoot id='AzZOk'></tfoot>

      2. <small id='AzZOk'></small><noframes id='AzZOk'>

      3. <i id='AzZOk'><tr id='AzZOk'><dt id='AzZOk'><q id='AzZOk'><span id='AzZOk'><b id='AzZOk'><form id='AzZOk'><ins id='AzZOk'></ins><ul id='AzZOk'></ul><sub id='AzZOk'></sub></form><legend id='AzZOk'></legend><bdo id='AzZOk'><pre id='AzZOk'><center id='AzZOk'></center></pre></bdo></b><th id='AzZOk'></th></span></q></dt></tr></i><div id='AzZOk'><tfoot id='AzZOk'></tfoot><dl id='AzZOk'><fieldset id='AzZOk'></fieldset></dl></div>

          <bdo id='AzZOk'></bdo><ul id='AzZOk'></ul>

                <tbody id='AzZOk'></tbody>
            • <legend id='AzZOk'><style id='AzZOk'><dir id='AzZOk'><q id='AzZOk'></q></dir></style></legend>
                  本文介绍了Number().toLocaleString() 在不同的浏览器中有不同的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我将浮点数格式化为语言环境字符串(欧元),每个浏览器中的结果都大不相同.没有自己的功能可以修复吗?

                  I format a float to a locale string (Euro) and there are very different results in every browser. Is it possible to fix without an own function?

                  var sum=2282.0000;
                  var formated_sum = Number(sum.toFixed(2)).toLocaleString("de-DE", {style: "currency", currency: "EUR"});
                  

                  Firefox 结果:2.282,00 €

                  Firefox result: 2.282,00 €

                  Chrome 结果:2.282 €

                  Chrome result: 2.282 €

                  IE 结果:2.282,00 €

                  IE result: 2.282,00 €

                  Safari 结果:2282 欧元

                  Safari result: 2282 €

                  Safari 的结果非常错误,chrome 的结果并没有那么糟糕.任何想法如何在不编写自己的格式化函数的情况下解决这个问题?

                  Safari results are very much wrong, chrome results are not so much bad. Any Idea how to fix that without writing an own function for formatting?

                  这个问题在这里可能已经有了答案:toLocaleString() 在不同浏览器中的行为不一致不,我的问题不同,因为我正在寻找货币的解决方案,而不是日期

                  This question may already have an answer here: Inconsistent behavior of toLocaleString() in different browser No, my question is different because i am searching for a solution for Currency, not DATE

                  推荐答案

                  ECMA 262 指定函数依赖于实现并且不带参数.

                  ECMA 262 specifies that the function is implementation dependent and takes no arguments.

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

                  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.

                  注意此函数的第一个参数可能用于本标准的未来版本;建议实现不会将此参数位置用于其他任何事情.

                  NOTE The first parameter to this function is likely to be used in a future version of this standard; it is recommended that implementations do not use this parameter position for anything else.

                  它也在 ECMA 国际化 API 规范中(其中Number.prototype.toLocaleString 取代 ECMA 262 但接受 2 个参数)

                  It is also in ECMA internationalization API specification (which for Number.prototype.toLocaleString supersedes ECMA 262 but accepts 2 arguments)

                  此定义取代 ES5 15.7.4.3 中提供的定义.

                  This definition supersedes the definition provided in ES5, 15.7.4.3.

                  当使用可选参数调用 toLocaleString 方法时语言环境和选项,采取以下步骤:

                  When the toLocaleString method is called with optional arguments locales and options, the following steps are taken:

                  让 x 是这个 Number 值(在 ES5, 15.7.4 中定义).如果语言环境是未提供,则让语言环境未定义.如果选项不是提供,然后让选项未定义.让 numberFormat 为创建一个新对象的结果,就像通过表达式 newIntl.NumberFormat(locales, options) 其中 Intl.NumberFormat 是11.1.3 中定义的标准内置构造函数.返回结果调用 FormatNumber 抽象操作(在 11.3.2 中定义)参数 numberFormat 和 x.长度属性的值toLocaleString 方法为 0.

                  Let x be this Number value (as defined in ES5, 15.7.4). If locales is not provided, then let locales be undefined. If options is not provided, then let options be undefined. Let numberFormat be the result of creating a new object as if by the expression new Intl.NumberFormat(locales, options) where Intl.NumberFormat is the standard built-in constructor defined in 11.1.3. Return the result of calling the FormatNumber abstract operation (defined in 11.3.2) with arguments numberFormat and x. The value of the length property of the toLocaleString method is 0.

                  此外,mdn指定 Safari 不支持它.

                  Besides, mdn specifies that Safari has no support for it.

                  至于可行的解决方案,请参阅this answer on SO

                  As for a viable solution see this answer on SO

                  这篇关于Number().toLocaleString() 在不同的浏览器中有不同的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 1.5K、1M、1G 等公制前缀格式化 javascript 数字 下一篇:是否可以在 Dreamweaver 中自动格式化您的代码?

                  相关文章

                  最新文章

                  <i id='AKyGX'><tr id='AKyGX'><dt id='AKyGX'><q id='AKyGX'><span id='AKyGX'><b id='AKyGX'><form id='AKyGX'><ins id='AKyGX'></ins><ul id='AKyGX'></ul><sub id='AKyGX'></sub></form><legend id='AKyGX'></legend><bdo id='AKyGX'><pre id='AKyGX'><center id='AKyGX'></center></pre></bdo></b><th id='AKyGX'></th></span></q></dt></tr></i><div id='AKyGX'><tfoot id='AKyGX'></tfoot><dl id='AKyGX'><fieldset id='AKyGX'></fieldset></dl></div>

                    <tfoot id='AKyGX'></tfoot>
                    <legend id='AKyGX'><style id='AKyGX'><dir id='AKyGX'><q id='AKyGX'></q></dir></style></legend>

                      • <bdo id='AKyGX'></bdo><ul id='AKyGX'></ul>

                      <small id='AKyGX'></small><noframes id='AKyGX'>