Method: Float#to_int

Defined in:
numeric.c

#to_iInteger #to_intInteger

Returns the float truncated to an Integer.

1.2.to_i      #=> 1
(-1.2).to_i   #=> -1

Note that the limited precision of floating point arithmetic might lead to surprising results:

(0.3 / 0.1).to_i  #=> 2 (!)

#to_int is an alias for #to_i.

Overloads:


2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
# File 'numeric.c', line 2397

static VALUE
flo_to_i(VALUE num)
{
    double f = RFLOAT_VALUE(num);

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

    return dbl2ival(f);
}