• Post Reply Bookmark Topic Watch Topic
  • New Topic

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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!