Rounding problem

Hi,

I have a strange problem with number rounding: If I try "a_number.round(2)" in console - it works, but the same line thru passenger fails: "wrong number of arguments (1 for 0)". Any ideas why?

I'm running rails 2.3.4 and passenger 2.2.9

Hi,

I have a strange problem with number rounding:

If I try “a_number.round(2)” in console - it works, but the same line

thru passenger fails: “wrong number of arguments (1 for 0)”.

Any ideas why?

I’m running rails 2.3.4 and passenger 2.2.9

Hi, what’s the value of a_number being used?

-Conrad

Hi,

I have a strange problem with number rounding: If I try "a_number.round(2)" in console - it works, but the same line thru passenger fails: "wrong number of arguments (1 for 0)". Any ideas why?

Is a_number an integer ? rails overrides round to allow it to take a precision argument, but it only does that on Float - Integers still have the standard round method, which does not take a precision argument.

Fred

Thanks for the answers - This solved my problem partly. In database (mysql) the number is a decimal - but for some reason it seems to be an integer in rails if it's decimals are zeros.

Janne

class Float   def round_to(x)     (self * 10**x).round.to_f / 10**x   end end

then you can use round_to(2)

Sincerely,

Joel Dezenzio Website Bio: http://jdezenzio.com/ Rails Production Sites: http://ncaastatpages.com

To avoid floating point errors, you might as well just do : (self * 1.0).round.(x) or self.to_f.round.(x)

And wouldn't that be a patch to class Integer, as Float already has .round working fine? Or am I missing something ?:-/

what is the range of values that you’re working with? 0 to 100, -3000 to 4000?