• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Please help! Urgent!  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Is there any way in Java for rounding of the numbers to two digits. For example the number "2.901614044112919" should be like "2.91" or "2.92". I used the Math functions "ceil,round & floor", does not seems to be helping me to get the desired the result.
Please reply ASAP.
Appreciate yr help.
Thanks in advance
Regards
Krishna
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this:
double val = 2.901614044112919;
DecimalFormat formatter = new DecimalFormat("#.##");
String output = formatter(val);
System.out.println("output: " + output);
check out this: http://java.sun.com/docs/books/tutorials/il8n/format/decimalFormat.html
Hope this helps!
Good luck
 
Krishna Nagesh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mindy!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!