Yeah that's pretty much the key point - that return type of invoking
the / method of integer and passing it a decimal is a decimal type
cast.

On Jul 12, 12:45 pm, Dave Aronson <googlegroups2d...@davearonson.com>
wrote:
> On Thu, Jul 12, 2012 at 1:13 AM, John Merlino <stoici...@aol.com> wrote:
> > (@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.
>
> To clarify (and expand, thus re-muddying) the preceding answers somewhat:
>
> If a mathematical expression is written with only integers, most
> languages will assume that you want an integer answer.  How it will
> deal with the remainder may vary, such as rounding, truncation, or
> "banker's rounding".  (IIRC VB or some such thing uses that.  The
> difference from normal rounding is that normally halves round up,
> while in banker's rounding, halves round to whichever way gives an
> even number.)
>
> So, you use .0 to turn one of those integers into a floating point number.
>
> You can achieve the same thing with a multiplication by 1.0.  You'll
> see this used where the numbers are variables rather than literals,
> especially in languages that make you declare a variable's type, and
> distinguish between integers and floating point numbers.
>
> Either way, in a complicated expression, you may need to be careful
> about *which* literal you tack .0 onto, or *when* you multiply by 1.0.
>  Getting that wrong may wind up with some deeper parts of the
> expression yielding integer results, when you really wanted a float.
>
> -Dave
>
> --
>  Dave Aronson, Cleared/Remote Ruby on Rails Freelancer
> (NoVa/DC/Remote); seewww.DaveAronson.com, and blogs 
> atwww.Codosaur.us,www.Dare2XL.com,www.RecruitingRants.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@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-US.

Reply via email to