Rounding UP by 0.05

I am almost there but not quite. I need to round UP the computed tax
amount to the nearest 5 cents (or $ 0.05). I have gotten to the point
where I can round (up or down) to the nearest 5 cents. Here is my
funtion:

computer the tax for each item given quantity, price, and percent tax

def compute_tax(quantity, price, percent_tax)
raw_value = (quantity * price * (percent_tax/100.0))
rounded_value = (raw_value * 20).round / 20.0
rounded_value
end

This does not work for the cases where the computation of raw_value
works out to something like 0.5625 for example. The function shown
above returns 0.55. I would like it to return 0.60 in such cases.
Cannot figure this out.

Appreciate any help in advance.

Thanks.

Bharat

Afternoon,

On Thu, Sep 9, 2010 at 4:08 PM, Bharat R. [email protected]
wrote:

rounded_value = (raw_value * 20).round / 20.0

rounded_value = (raw_value * 20).ceil / 20.0

John

I couldn’t catch you that much, but I tried something like:

(0.5625*10).ceil.to_f/10 # => 0.6

That will round the number always up.

I don’t know if that would help you.

Daniel Gaytán
http://survey.richapplabs.com/index.php?sid=62661&lang=en

2010/9/9 Bharat R. [email protected]

rounded_value = (raw_value * 20).ceil / 20.0

works like a charm. Many thanks.

Bharat