+ 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?

1st Feb 2019, 12:40 PM
Min Somai
Min Somai - avatar
2 Respostas
+ 4
b=2.2; Formatter fmt=new Formatter(); fmt.format("%.4f",b); print(fmt); output: 2.2000
3rd Feb 2019, 9:23 AM
Himani
0
If you want to only print up to a certain decimal place, you can use: System.out.printf("%4f",a);
3rd Feb 2019, 9:20 AM
Tibor Santa
Tibor Santa - avatar