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

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

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

      1. 如何确保 javascript 添加而不是字符串连接(不总是添加整数)

        时间:2023-06-13

      2. <tfoot id='skxJQ'></tfoot>
        <legend id='skxJQ'><style id='skxJQ'><dir id='skxJQ'><q id='skxJQ'></q></dir></style></legend>

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

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

                • 本文介绍了如何确保 javascript 添加而不是字符串连接(不总是添加整数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  通过我的 javascript 库,我得到了一个代表数字的字符串.现在我想对该数字进行加法运算,而不是进行字符串连接.解决方法很简单(怎么做我使用 javascript (jquery) 将整数值添加到返回字符串的值中?、).但是我的字符串可以是浮点数或整数,并且在添加时,我不知道它会是哪个.有没有办法确保无论是浮点数还是整数都发生加法?

                  Through my javascript library, I end up with a string that represents a number. Now I want to preform an addition on that number without it doing a string concatenation instead. The solution is easy ( How do I add an integer value with javascript (jquery) to a value that's returning a string?, How to make an addition instead of a concatenation) if your number is always in integer. However my string could be a float or an integer, and at the time of the addition, and I don't know which it will be. Is there a way to make sure the addition happens regardless of whether it's a float or integer?

                  推荐答案

                  尝试使用 parseFloat.输入变量将被转换为浮点数,无论字符串包含整数还是浮点数都有效.您的结果将始终为浮点数.

                  Try using parseFloat. The input variables will be converted to floats, which will work whether the string contains an integer or a float. Your result will always be a float.

                  这篇关于如何确保 javascript 添加而不是字符串连接(不总是添加整数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝 下一篇:JavaScript - 防止八进制转换

                  相关文章

                  <legend id='24Dme'><style id='24Dme'><dir id='24Dme'><q id='24Dme'></q></dir></style></legend>
                    <bdo id='24Dme'></bdo><ul id='24Dme'></ul>

                    <small id='24Dme'></small><noframes id='24Dme'>

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