<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 to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  <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>