Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rounding a float value upto 2 decimal places

 
Lucky Chawla
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Lucky Chawla
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i did a small mistake..but now it is working for me..

Thanks
Lucky
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic