<legend id='60gpt'><style id='60gpt'><dir id='60gpt'><q id='60gpt'></q></dir></style></legend>
    1. <small id='60gpt'></small><noframes id='60gpt'>

        <bdo id='60gpt'></bdo><ul id='60gpt'></ul>
      <tfoot id='60gpt'></tfoot>

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

        Javascript:格式化数字的更简单方法?

        时间:2023-05-29

        1. <small id='hzRZb'></small><noframes id='hzRZb'>

          • <bdo id='hzRZb'></bdo><ul id='hzRZb'></ul>
            <legend id='hzRZb'><style id='hzRZb'><dir id='hzRZb'><q id='hzRZb'></q></dir></style></legend>
              <tbody id='hzRZb'></tbody>

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

                • 本文介绍了Javascript:格式化数字的更简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试格式化页面上的各种数字.这些数字代表价格、价格变化或百分比.我知道 Javascript 具有限制小数位数的功能,但是是否支持其他类型的格式,例如用逗号对数字进行分组,控制是否显示 +/- 等?到目前为止,这是我所拥有的:

                  I'm trying to format various numbers on my page. These numbers either represent a price, a change in price, or a percentage. I know Javascript has functions to limit the number of decimal places, but is there any support for other types of formatting, such as grouping numbers with commas, controlling whether or not the +/- is shown, etc? Here's what I have so far:

                  var FORMATTER = {
                      price       : function(value) { return '$' + value.toFixed(2); },
                      pricePer    : function(value) { return (value * 100).toFixed(2) + '%'; },
                      priceChg    : function(value) { return (value >= 0 ? '+' : '-') + '$' + Math.abs(value).toFixed(2); }
                  };
                  

                  它工作正常,但它想在price"格式化程序中添加逗号,您可以看到priceChg"格式化程序中有一个黑客,我尝试将 +/- 符号移到'$' 符号.

                  It works OK, but it'd like to add commas to the 'price' formatter, and you can see that there's a hack in the 'priceChg' formatter where I try to move the +/- sign in front of the '$' sign.

                  基本上,我希望有一些库可以模拟 Java 的 DecimalFormat 类.

                  Basically, I'm hoping there is some library out there (jQuery is OK) that emulates Java's DecimalFormat class.

                  推荐答案

                  这里有NUMBERFORMATTER jQuery插件,详情如下:

                  There's the NUMBERFORMATTER jQuery plugin, details below:

                  https://code.google.com/p/jquery-numberformatter/

                  从上面的链接:

                  这个插件是一个 NumberFormatter插入.数字格式可能与任何合作过的人都熟悉服务器端代码,如 Java 或 PHP 和谁合作过国际化.

                  This plugin is a NumberFormatter plugin. Number formatting is likely familiar to anyone who's worked with server-side code like Java or PHP and who has worked with internationalization.

                  将链接替换为更直接的链接.

                  Replaced the link with a more direct one.

                  这篇关于Javascript:格式化数字的更简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:jquery嵌套ajax调用格式化 下一篇:如何将 NUnit 输出转换为 HTML 报告

                  相关文章

                  最新文章

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

                  • <bdo id='Ws7NZ'></bdo><ul id='Ws7NZ'></ul>
                  <tfoot id='Ws7NZ'></tfoot>

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