+ 1
Round up decimal but put zero for round up less tha N.
eg. I have a = 2.003473 b = 2.2 and I want to round up to 4 decimal. output expectation . a = 2.0034 b = 2.2000 how to get value for b?
2 Respuestas
+ 4
b=2.2;
Formatter fmt=new Formatter();
fmt.format("%.4f",b);
print(fmt);
output:
2.2000
0
If you want to only print up to a certain decimal place, you can use:
System.out.printf("%4f",a);