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

          <bdo id='6920g'></bdo><ul id='6920g'></ul>

        <legend id='6920g'><style id='6920g'><dir id='6920g'><q id='6920g'></q></dir></style></legend>

      1. 如何从 JavaScript 数字中删除小数部分?

        How can I remove the decimal part from JavaScript number?(如何从 JavaScript 数字中删除小数部分?)

          <tbody id='Umpgc'></tbody>
      2. <legend id='Umpgc'><style id='Umpgc'><dir id='Umpgc'><q id='Umpgc'></q></dir></style></legend>
      3. <small id='Umpgc'></small><noframes id='Umpgc'>

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

                <tfoot id='Umpgc'></tfoot>

                  本文介绍了如何从 JavaScript 数字中删除小数部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有除法的结果,我希望舍弃结果数的小数部分.

                  I have the results of a division and I wish to discard the decimal portion of the resultant number.

                  我该怎么做?

                  推荐答案

                  你可以使用...

                  • Math.trunc()(截断小数部分,另见下文)
                  • Math.floor()(向下取整)
                  • Math.ceil()(四舍五入)
                  • Math.round()(四舍五入到最接近的整数)

                  ...取决于您要如何删除小数.

                  ...dependent on how you wanted to remove the decimal.

                  Math.trunc() 尚不支持所有平台(即 IE),但您可以轻松使用 polyfill 同时.

                  Math.trunc() isn't supported on all platforms yet (namely IE), but you could easily use a polyfill in the meantime.

                  另一种截断小数部分并具有出色平台支持的方法是使用 位运算符 (.eg |0).对数字使用按位运算符的副作用是将其操作数视为带符号的 32 位整数,因此会删除小数部分.请记住,这也会破坏大于 32 位的数字.

                  Another method of truncating the fractional portion with excellent platform support is by using a bitwise operator (.e.g |0). The side-effect of using a bitwise operator on a number is it will treat its operand as a signed 32bit integer, therefore removing the fractional component. Keep in mind this will also mangle numbers larger than 32 bits.

                  您可能还在谈论浮点运算的十进制舍入的不准确性.

                  You may also be talking about the inaccuracy of decimal rounding with floating point arithmetic.

                  必读 - 每个计算机科学家都应该知道的浮点运算.

                  这篇关于如何从 JavaScript 数字中删除小数部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                    <tbody id='YNeTq'></tbody>

                  1. <tfoot id='YNeTq'></tfoot>
                      • <legend id='YNeTq'><style id='YNeTq'><dir id='YNeTq'><q id='YNeTq'></q></dir></style></legend>

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

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