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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Mar 30, 2010 at 1:21 AM, JanneKo <janne.s.konttila-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 30, 9:21 am, JanneKo <janne.s.kontt...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> > I''m running rails 2.3.4 and passenger 2.2.9-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 30, 9:21 am, JanneKo <janne.s.kontt...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > > > > I''m running rails 2.3.4 and passenger 2.2.9-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 30 March 2010 15:40, Joel Dezenzio <jdezenzio-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> class Float > def round_to(x) > (self * 10**x).round.to_f / 10**x > end > endTo 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 ?:-/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
what is the range of values that you''re working with? 0 to 100, -3000 to 4000? On 30 March 2010 04:21, JanneKo <janne.s.konttila-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Charles A. Lopez charlesalopez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org What''s your vision for your organization? What''s your biggest challenge? Let''s talk. (IBM Partner) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.