Re: [Rails] ceil method
Let's ask irb:
1.9.2-p320 :002 > 3/2
=> 1
1.9.2-p320 :003 > 3.0/2
=> 1.5
Walter
On Jul 12, 2012, at 1:13 AM, John Merlino wrote:
> Often times the ceil method is used for patterns that involve grouping. For example, if I have an array of objects and I want to group them in rows of 3, I might do this:
>
> (@objects.size / 3.0).ceil
>
> So if size returns 2, then the above expression returns 1.
>
> Here's my question. In terms of arithmetic, I dont understand why 3.0 must be used and not just 3. If I was to calculate 2/3.0 and 2/3 in a calculator, it returns same result, after all, since .0 is meaningless. Its like 3.00 or 3.0000 it all means the same. So why does ceil return different results with 2/3.0 and 2/3?
>
> thanks for response
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/nln7GDpfo7sJ.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> 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-US.
--
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@googlegroups.com.
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-US.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home