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

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

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

      <legend id='zF0Sd'><style id='zF0Sd'><dir id='zF0Sd'><q id='zF0Sd'></q></dir></style></legend>

        将尾随零添加到整数而不转换为JS中的字符串?

        Add trailing zeros to an integer without converting to string in JS?(将尾随零添加到整数而不转换为JS中的字符串?)

            <tfoot id='QMOQW'></tfoot>
            • <small id='QMOQW'></small><noframes id='QMOQW'>

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

                  本文介绍了将尾随零添加到整数而不转换为JS中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望在整数末尾添加小数.举个例子:

                  I'm looking to add decimals to the end of my integer. As an example:

                  15 => 15.00

                  15 => 15.00

                  toFixed 等方法的问题在于它会将其转换为字符串.我尝试在字符串上使用 parseFloat() 和 Number(),但它会将其转换回没有小数的整数.

                  The problem with methods like toFixed is that it will convert it into a string. I've tried to use parseFloat() and Number() on the string, but it'll convert it back to an integer with no decimals.

                  这可能吗?如果不是,有人可以向我解释为什么这是不可能的背后的逻辑吗?

                  Is this possible? If not, can someone explain to me the logic behind why this isn't possible?

                  Welp 的意图是将数字显示为数字,但从目前的共识来看,似乎唯一的方法是使用字符串.找到了原因的答案:https://stackoverflow.com/a/17811916/8869701

                  Welp the intent was to display the number as a number, but from the going consensus, it looks like the way the only way to go about it is to use a string. Found an answer on the why: https://stackoverflow.com/a/17811916/8869701

                  推荐答案

                  您发现的问题是javascript中的所有数字都是浮点数.

                  The problem you are finding is that all numbers in javascript are floats.

                  a = 0.1
                  typeof a # "number"
                  
                  b = 1
                  typeof b # number
                  

                  它们是一样的.

                  所以没有真正的方法可以将整数转换为浮点数.

                  So there is no real way to convert to from an integer to a float.

                  这就是所有 parseFloat 等都是用于从字符串中读取和写入数字的字符串方法的原因.即使你确实有浮点数和整数,指定一个数字的精度只有在你向用户显示它时才真正有意义,为此它无论如何都会被转换为字符串.

                  This is the reason that all of the parseFloat etc are string methods for reading and writing numbers from strings. Even if you did have floats and integers, specifying the precision of a number only really makes sense when you are displaying it to a user, and for this purpose it will be converted to a string anyway.

                  根据您的具体用例,如果您想以定义的精度显示,则需要使用字符串.

                  Depending on your exact use case you will need to use strings if you want to display with a defined precision.

                  这篇关于将尾随零添加到整数而不转换为JS中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What are valid deviceNames for Chrome emulation testing with Protractor?(使用 Protractor 进行 Chrome 模拟测试的有效设备名称是什么?)
                  Protractor Check if Element Does Not Exist(量角器检查元素是否不存在)
                  Protractor e2e Tests Login Redirection(Protractor e2e 测试登录重定向)
                  Explain about async/ await in Protractor(解释 Protractor 中的 async/await)
                  Protractor browser.wait doesn#39;t wait(量角器 browser.wait 不等待)
                  How to use Protractor with Angular 2?(如何在 Angular 2 中使用量角器?)
                  <legend id='Diq3n'><style id='Diq3n'><dir id='Diq3n'><q id='Diq3n'></q></dir></style></legend>

                  1. <tfoot id='Diq3n'></tfoot>

                    • <bdo id='Diq3n'></bdo><ul id='Diq3n'></ul>
                    • <small id='Diq3n'></small><noframes id='Diq3n'>

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