Java四舍五入,如double类型1.44449,保留小数点后一位,要求答案是1.5
问题描述:
Java四舍五入,如double类型1.44449,保留小数点后一位,要求答案是1.5
答
public class floor {
public static void main(String args[]) {
double a = 1.4444449;
double c = 1000000;
double b = 0;
int i = 6;
while(i > 0) {
b = Math.ceil(a * c);
a = a/ 10;
i--;
}
System.out.println(b/10);
}
}