the trailboss abuses his CodeRanch power for his other stuff (power corrupts. absolute power corrupts absolutely is kinda neat!)
permaculture light bulbs permaculture electric heat permaculture cast iron permaculture wood burning stove permaculture solar food dehydrators
The moose likes Meaningless Drivel and the fly likes Rounding decimal number to nearest 0.05 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Meaningless Drivel
Bookmark "Rounding decimal number to nearest 0.05" Watch "Rounding decimal number to nearest 0.05" New topic
Author

Rounding decimal number to nearest 0.05

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I want to round decimal number to nearest 0.05. Let me know if the following examples are correct.

12.325 becomes 12.33 and gets rounded to 12.35.
12.315 becomes 12.32 -> 12.30
12.323 ->12.32->12.30
12.399->12.40
12.385->12.40
thanks


Groovy
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Anyone ?
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Rules for Rounding


My blood is tested +ve for Java.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Thanks Chetan.
Actually the formula is quite simple

Round(A*20)/20.
 
Consider Paul's rocket mass heater.
 
subject: Rounding decimal number to nearest 0.05