This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

rounding off

 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
double d=3.95;
System.out.printf("%.1f",d);
output is 4........
so 3.95 gets rounded to 4.....3.91 to 3.92 is rounded to 3.9 and 3.95 to 3.99 is rounded to 4.0



output is 124 4.0

is there any other rule that i should know about or this is it......
 
Aneesh Vijendran
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure why you want to use the

%.0f %.1f
option.

If you just print:

System.out.printf(d1 + " " + d2);

Will show you the desired effect.

Else Use java.text.DecimalFormat




Cheers
Aneesh
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic