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

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

        如果一千或更多,则将数字格式化为 2.5K,否则为

        时间:2023-05-29
          <bdo id='2K5w0'></bdo><ul id='2K5w0'></ul>
              <tbody id='2K5w0'></tbody>

                • <tfoot id='2K5w0'></tfoot>
                • <small id='2K5w0'></small><noframes id='2K5w0'>

                • <legend id='2K5w0'><style id='2K5w0'><dir id='2K5w0'><q id='2K5w0'></q></dir></style></legend>
                  <i id='2K5w0'><tr id='2K5w0'><dt id='2K5w0'><q id='2K5w0'><span id='2K5w0'><b id='2K5w0'><form id='2K5w0'><ins id='2K5w0'></ins><ul id='2K5w0'></ul><sub id='2K5w0'></sub></form><legend id='2K5w0'></legend><bdo id='2K5w0'><pre id='2K5w0'><center id='2K5w0'></center></pre></bdo></b><th id='2K5w0'></th></span></q></dt></tr></i><div id='2K5w0'><tfoot id='2K5w0'></tfoot><dl id='2K5w0'><fieldset id='2K5w0'></fieldset></dl></div>
                  本文介绍了如果一千或更多,则将数字格式化为 2.5K,否则为 900的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我需要以 1K 等于一千的格式显示一个货币值,或者 1.1K, 1.2K, 1.9K等,如果不是偶数千,否则如果小于千,显示正常500,100,250 等,使用 JavaScript 格式化数字?

                  I need to show a currency value in the format of 1K of equal to one thousand, or 1.1K, 1.2K, 1.9K etc, if its not an even thousands, otherwise if under a thousand, display normal 500, 100, 250 etc, using JavaScript to format the number?

                  推荐答案

                  听起来应该适合你:

                  function kFormatter(num) {
                      return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
                  }
                      
                  console.log(kFormatter(1200)); // 1.2k
                  console.log(kFormatter(-1200)); // -1.2k
                  console.log(kFormatter(900)); // 900
                  console.log(kFormatter(-900)); // -900

                  这篇关于如果一千或更多,则将数字格式化为 2.5K,否则为 900的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么 HTML 要求多个空格在浏览器中显示为单个 下一篇:在jQuery中将逗号添加到数字

                  相关文章

                  最新文章

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

                • <small id='8CmjH'></small><noframes id='8CmjH'>

                  1. <tfoot id='8CmjH'></tfoot>
                      • <bdo id='8CmjH'></bdo><ul id='8CmjH'></ul>
                      <legend id='8CmjH'><style id='8CmjH'><dir id='8CmjH'><q id='8CmjH'></q></dir></style></legend>