Java int vs. Double [英] Java int vs. Double
本文介绍了Java int vs. Double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public double calc(int v1) {
return v1 / 2 + 1.5;
}
public double cald (double v) {
return v / 2 + 1.5;
}
函数返回相同的结果吗?
Do the functions return the same result?
我认为它们不会返回相同的结果,因为第二个函数会包含小数点,而第二个函数会将数字四舍五入。
I would argue that they don't return the same result, as the second function would include the decimal point, where as the second function would round the number up.
这是正确的吗?
推荐答案
当你划分 a
by b
ie a / b
when you divide a
by b
i.e a/b
if a
& b
是 int
然后结果将是 int
其他任意或两者 a
& b
double
然后结果将是 double
if both a
& b
are int
then result will be int
else any or both a
& b
are double
then result will be double
修改:
另请参阅我对此问题的回答简单划分问题
Also see my answer to this Question Simple Divide Problem
这篇关于Java int vs. Double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文