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

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

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

      1. <legend id='IdWQA'><style id='IdWQA'><dir id='IdWQA'><q id='IdWQA'></q></dir></style></legend>
      2. toString(36) 的对面?

        时间:2023-08-07
          <legend id='xqHCe'><style id='xqHCe'><dir id='xqHCe'><q id='xqHCe'></q></dir></style></legend>

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

                  本文介绍了toString(36) 的对面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  var a = (123.456).toString(36)//"3f.gez4w97ry0a18ymf6qadcxr"

                  现在,如何使用该字符串恢复为原始数字?

                  Now, how do I revert back to the original number using that string?

                  注意:parseInt(number,36) 仅适用于整数.

                  Note: parseInt(number,36) only works for integers.

                  推荐答案

                  您可以尝试使用 parseInt 分别解析整数和浮点部分,因为 parseFloat 不支持基数:

                  You could try parsing the integer and float parts separately with parseInt, as parseFloat does not support a radix:

                  function parseFloatInBase(n, radix) {
                      var nums = n.split(".")
                  
                      // get the part before the decimal point
                      var iPart = parseInt(nums[0], radix)
                      // get the part after the decimal point
                      var fPart = parseInt(nums[1], radix) / Math.pow(radix, nums[1].length)
                  
                      return iPart + fPart
                  }
                  
                  // this will log 123.456:
                  console.log(parseFloatInBase("3f.gez4w97ry0a18ymf6qadcxr", 36))
                  

                  我除以 radix ^ numLength 因为我基本上是在 numLength 空格上移动小数点.你会像在数学课上那样做,因为你知道除以 10 会将小数移动一个空格,因为大多数数学都是以 10 为底的.示例:

                  I am dividing by radix ^ numLength because I am basically moving the decimal point over numLength spaces. You would do this just like in math class, because as you know dividing by 10 moves the decimal over one space, because most math is in base 10. Example:

                  123456 / 10 / 10 / 10 = 123.456
                  

                  这相当于

                  123456 / (10 * 10 * 10) = 123.456
                  

                  因此

                  123456 / (10 ^ 3) = 123.456
                  

                  这篇关于toString(36) 的对面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:.slice(0) 在这里有什么意义? 下一篇:Javascript:将字符串解析为日期作为本地时区

                  相关文章

                  最新文章

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

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

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