• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Rounding a float value upto 2 decimal places

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i did a small mistake..but now it is working for me..

Thanks
Lucky
 
reply
    Bookmark Topic Watch Topic
  • New Topic