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

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

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

    2. 意外结果导致长/整数除法

      Unexpected result in long/int division(意外结果导致长/整数除法)
        <bdo id='LIWG7'></bdo><ul id='LIWG7'></ul>

            <tbody id='LIWG7'></tbody>
          <tfoot id='LIWG7'></tfoot>

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

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

              <legend id='LIWG7'><style id='LIWG7'><dir id='LIWG7'><q id='LIWG7'></q></dir></style></legend>
                本文介绍了意外结果导致长/整数除法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有这样的价值观:

                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)

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

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

                相关文档推荐

                How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                How to convert Integer to int?(如何将整数转换为整数?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                Inconsistent behavior on java#39;s ==(java的行为不一致==)
                Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)
                  <legend id='0fh5a'><style id='0fh5a'><dir id='0fh5a'><q id='0fh5a'></q></dir></style></legend>

                      <bdo id='0fh5a'></bdo><ul id='0fh5a'></ul>

                    • <tfoot id='0fh5a'></tfoot>
                    • <small id='0fh5a'></small><noframes id='0fh5a'>

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