• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help! Urgent!  RSS feed

 
Krishna Nagesh
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
 
Mindy Wu
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!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!