Try this code
double num = 1001.27124;
double newNum = Math.round(num*100.0)/100.0;
System.out.println (newNum); //prints 1001.27
It works because *100 shifts the numbers to the left twice. Then the round is applied. Then we divide by 100 to shift twice right.
For more help, www.NeedProgrammingHelp.com
NPH
Junior Poster in Training
55 posts since May 2005
Reputation Points: 10
Solved Threads: 1
import java.util.*;
DecimalFormat dec = new DecimalFormat("###.##");
System.out.println(dec.format(value));
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
better to use the setMinimumFractionDigits and setMaximumFractionDigits functions on DecimalFormat.
The format strings can be confusing :)
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337