Tuesday, August 31, 2010

Rounding double to two decimal places in Java

This is the simplest way i found.

Double num = 2.554545;

DecimalFormat twoDForm = new DecimalFormat("#.##");
return Double.valueOf(twoDForm.format(num));

No comments:

Post a Comment