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.

## Recommended Answers

Jump to PostTry 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

Jump to Postimport java.util.*;

DecimalFormat dec = new DecimalFormat("###.##");

System.out.println(dec.format(value));

## All 7 Replies

NPH
0
Junior Poster in Training

server_crash
64
Postaholic

jwenting
1,839
duckman
Team Colleague

cheenu78
0
Light Poster

NavinBhutada
0
Newbie Poster

tong1
22
Posting Whiz

mubin_89
0
Newbie Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.