Java Double / Integer [英] Java Double/Integer
本文介绍了Java Double / Integer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int a = 1;
int b = 10;
int c = 3;
int d = (1/10)*3
System.out.println(d)
Result: 0
我如何使这个计算工作?
并向上或向下?
它应该是:
(1/10)* 3 = 0.1 * 3 = 0.3 = 0和
(4/10)* 3 = 0.4 * 3 = 1.2 = 1
How do i make this Calculation work ? and round up or down ? It should be: (1/10)*3 = 0.1 * 3 = 0.3 = 0 and (4/10)*3 = 0.4 * 3 = 1.2 = 1
非常感谢!
推荐答案
1 / 10
这是整数除法,整数除以结果为0.
然后0 * 3 = 0
This is integer division and as integer division the result is 0. Then 0 * 3 = 0
您可以使用双字面值:
1.0 / 10.0
这篇关于Java Double / Integer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文