On 30 March 2010 15:40, Joel Dezenzio <jdezen...@gmail.com> wrote:
> class Float
>  def round_to(x)
>    (self * 10**x).round.to_f / 10**x
>  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 ?:-/

-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to