aspose file tools*
The moose likes Java in General and the fly likes Rounding a float value upto 2 decimal places Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Rounding a float value upto 2 decimal places" Watch "Rounding a float value upto 2 decimal places" New topic
Author

Rounding a float value upto 2 decimal places

Lucky Chawla
Greenhorn

Joined: Aug 08, 2006
Posts: 22
Hi there, I want to display a float vlue with 2 decimal places
I trid using :
DecimalFormat df = new DecimalFormat("###.##");
df.format(l_tot_link);
but still get the same result like 12.1666 aor 1234.5099087 , I wnt to display it as 12.16 and 1234.50 .can anybody help me out with this
Luciano Mantuaneli
Greenhorn

Joined: Dec 04, 2006
Posts: 13
Although you don't posted how you try to print your result, I can guess you made it like this:

If you done something like that, you will have in your console the 12.1666 value indeed. You have to know that the format method don't modify the parameter.
Try something like this:


[]'s<br />Mantu<br /> <br />Sorry for my poor english...<br /> <br /><i>Time after time we lose sight of the way. Our causes cant see their effects</i> - Neil Peart
Lucky Chawla
Greenhorn

Joined: Aug 08, 2006
Posts: 22
yes i did a small mistake..but now it is working for me..

Thanks
Lucky
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rounding a float value upto 2 decimal places
 
Similar Threads
help with double
Floating point conversion
SetPrecision?
Dividing Ints
2 decimal places