Monday, June 30, 2014

Round a double to 2 decimal places

I think this is easier:
double time = 200.3456;
DecimalFormat df = new DecimalFormat("#.##");      
time = Double.valueOf(df.format(time));

System.out.println(time); // 200.35
Note that this will actually do the rounding for you, not just formatting.

No comments:

Post a Comment