<legend id='1k6ir'><style id='1k6ir'><dir id='1k6ir'><q id='1k6ir'></q></dir></style></legend>
  • <small id='1k6ir'></small><noframes id='1k6ir'>

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

      • <bdo id='1k6ir'></bdo><ul id='1k6ir'></ul>
      <tfoot id='1k6ir'></tfoot>

        为什么Java除以0.0时不抛出异常?

        时间:2023-05-29
          <legend id='8JxGX'><style id='8JxGX'><dir id='8JxGX'><q id='8JxGX'></q></dir></style></legend>
          <i id='8JxGX'><tr id='8JxGX'><dt id='8JxGX'><q id='8JxGX'><span id='8JxGX'><b id='8JxGX'><form id='8JxGX'><ins id='8JxGX'></ins><ul id='8JxGX'></ul><sub id='8JxGX'></sub></form><legend id='8JxGX'></legend><bdo id='8JxGX'><pre id='8JxGX'><center id='8JxGX'></center></pre></bdo></b><th id='8JxGX'></th></span></q></dt></tr></i><div id='8JxGX'><tfoot id='8JxGX'></tfoot><dl id='8JxGX'><fieldset id='8JxGX'></fieldset></dl></div>
                <bdo id='8JxGX'></bdo><ul id='8JxGX'></ul>

                  <small id='8JxGX'></small><noframes id='8JxGX'>

                    <tbody id='8JxGX'></tbody>
                  <tfoot id='8JxGX'></tfoot>
                  本文介绍了为什么Java除以0.0时不抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有代码来计算两个数字之间的百分比差异 - (oldNum - newNum)/oldNum * 100; - 其中两个数字都是 doubles.我希望在 oldNum 为 0 的情况下必须添加某种检查/异常处理.但是,当我对 oldNum 和 newNum 的值都为 0.0 进行测试运行时,执行继续进行,就好像什么都没发生并且没有引发错误一样.使用 ints 运行此代码肯定会导致算术除零异常.为什么Java在涉及到doubles时会忽略它?

                  I have code to calculate the percentage difference between 2 numbers - (oldNum - newNum) / oldNum * 100; - where both of the numbers are doubles. I expected to have to add some sort of checking / exception handling in case oldNum is 0. However, when I did a test run with values of 0.0 for both oldNum and newNum, execution continued as if nothing had happened and no error was thrown. Running this code with ints would definitely cause an arithmetic division-by-zero exception. Why does Java ignore it when it comes to doubles?

                  推荐答案

                  除以零的结果在数学上是undefined,可以用float/double表示(如NaN - 不是一个数字),但它在任何基本意义上都没有错.

                  The result of division by zero is, mathematically speaking, undefined, which can be expressed with a float/double (as NaN - not a number), it isn't, however, wrong in any fundamental sense.

                  由于整数必须包含特定的数值,因此在处理它们时必须在除以零时引发错误.

                  As an integer must hold a specific numerical value, an error must be thrown on division by zero when dealing with them.

                  这篇关于为什么Java除以0.0时不抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:int 类型的字面量 xyz 超出范围 下一篇:在Java中将布尔值转换为int

                  相关文章

                • <small id='HqWgf'></small><noframes id='HqWgf'>

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

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