public Method

Float.to_int

flt.to_i        integer
flt.to_int      integer
flt.truncate    integer

Returns flt truncated to an Integer.

Source Code

/*
*  call-seq:
*     flt.to_i       => integer
*     flt.to_int     => integer
*     flt.truncate   => integer
*  
*  Returns <i>flt</i> truncated to an <code>Integer</code>.
*/

static VALUE
flo_truncate(num)
   VALUE num;
{
   double f = RFLOAT(num)->value;
   long val;

   if (f > 0.0) f = floor(f);
   if (f < 0.0) f = ceil(f);

   if (!FIXABLE(f)) {
       return rb_dbl2big(f);
   }
   val = f;
   return LONG2FIX(val);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.