如何四舍五入到最接近的十?
问题描述:
如何在没有 if 语句的情况下将数字四舍五入到最接近的十?例如,98 到 100.
How can I round a number to the nearest ten with no if statements? For example, 98 to 100.
int num = 87;
double t;
double d = 1.0 * num; // d = 87.0
t = d/100;
System.out.println(t);
答
你可以使用Math.round(num/10.0) * 10
.