JAVA: how to format a double to 2 decimal places. SOLVED

bobcpg

Senior member
Nov 14, 2001
951
0
0
Programming in java and need to know how to format a double var to 2 decimal places.

ie;
x=3.256635
and i want x to equal 3.26 or 3.25 is ok too


thanks
-bob
 

bobcpg

Senior member
Nov 14, 2001
951
0
0
Solved this one myself


public static final double roundDouble(double d, int places) {
return Math.round(d * Math.pow(10, (double) places)) / Math.pow(10,(double)places);

}