 # Round a numeric value

Hello people

I'm developing a rails 3.0.9 app and I'm doing some calculations for
prices.

I need to do the following:

if I get (i.e.) 10.0 to 10.4 I need to store 10
if I get (i.e.) 10.5 to 10.9 I need to store 11

Is there a rails way to do this?, thanks for your help

I'm developing a rails 3.0.9 app and I'm doing some calculations for
prices.

I need to do the following:

if I get (i.e.) 10.0 to 10.4 I need to store 10
if I get (i.e.) 10.5 to 10.9 I need to store 11

Is there a rails way to do this?, thanks for your help

Ruby, not Rails -- read the doc for BigDecimal, which is what you
should be using for prices.

amount = BigDecimal.new("10.5")

=> #<BigDecimal:101294c88,'0.105E2',18(18)>

amount.round

=> 11

amount = BigDecimal.new("10.4")

=> #<BigDecimal:10128c1c8,'0.104E2',18(18)>

amount.round

=> 10

HTH,

Thanks Hassan, that works for me

Yep, I was thinking abou to say exactaly the same thing as the guy above! For round a number I am using the bigdecimal class and the method round!

I think it is the best way to do it!

regards