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

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

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

      1. <legend id='PZaCV'><style id='PZaCV'><dir id='PZaCV'><q id='PZaCV'></q></dir></style></legend>

        <tfoot id='PZaCV'></tfoot>
      2. 意外结果导致长/整数除法

        时间:2023-10-02
          <tbody id='ntHN6'></tbody>

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

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

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

            <tfoot id='ntHN6'></tfoot>

                1. 本文介绍了意外结果导致长/整数除法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有这样的价值观:

                  long millis = 11400000;int 常数 = 86400000;双分辨率 = 毫/常数;

                  问题是:为什么 res 等于 0.0(而不是 ca. 0.131944)?它存储在 double 中,所以应该没有四舍五入吧?

                  解决方案

                  当你使用二元运算符时,两个参数的类型应该相同,结果也应该是它们的类型.当你想划分 (int)/(long) 它变成 (long)/(long) 结果是 (long).您应该将其设为 (double)/(long)(int)/(double) 以获得双重结果.由于 double 大于 int 和 long,所以 int 和 long 在 (double)/(long)(int)/(double)

                  I have values like this:

                  long millis = 11400000;
                  int consta = 86400000;
                  double res = millis/consta;
                  

                  The question is: why res equals 0.0 (instead of ca. 0.131944)? It's stored in double so there should be no rounding right?

                  解决方案

                  When you are using a binary operator, both arguments should be of a same type and the result will be in their type too. When you want to divide (int)/(long) it turns into (long)/(long) and the result is (long). you shouldmake it (double)/(long) or (int)/(double) to get a double result. Since double is greater that int and long, int and long will be turned into double in (double)/(long) and (int)/(double)

                  这篇关于意外结果导致长/整数除法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Java 是否具有 Integer、Float、Double、Long 的可变类型 下一篇:为什么 Java 能够将 0xff000000 存储为 int?

                  相关文章

                  最新文章

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

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

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

                      <tfoot id='IWPMt'></tfoot>