长/内分裂意外的结果

编程入门 行业动态 更新时间:2024-10-26 01:19:58
本文介绍了长/内分裂意外的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样的价值:

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

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

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?

推荐答案

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

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)

更多推荐

长/内分裂意外的结果

本文发布于:2023-11-13 14:16:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584544.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意外

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!