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

On Tue, Mar 30, 2010 at 1:21 AM, JanneKo [email protected]
wrote:

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

On Mar 30, 9:21 am, JanneKo [email protected] wrote:

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

On 30 maalis, 12:30, Frederick C. [email protected]

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

then you can use round_to(2)

Sincerely,

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

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

On 30 March 2010 04:21, JanneKo [email protected] wrote:

You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Charles A. Lopez
[email protected]

What’s your vision for your organization?
What’s your biggest challenge?

Let’s talk.
(IBM Partner)

On 30 March 2010 15:40, Joel D. [email protected] wrote:

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

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 ?:-/