Can anyone help me to get the estimate value of float value 1001.27124 to 1001.27? Math.round(float) function return the int value. But I want to get float value result with 2 decimal point; Thanks in advance.
Jump to Post
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
All 7 Replies
Be a part of the DaniWeb community
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.