Method: Rational#floor
- Defined in:
- rational.c
#floor([ndigits]) ⇒ Integer
Returns the largest number less than or equal to rat
with a precision of ndigits
decimal digits (default: 0).
When the precision is negative, the returned value is an integer with at least ndigits.abs
trailing zeros.
Returns a rational when ndigits
is positive, otherwise returns an integer.
Rational(3).floor #=> 3
Rational(2, 3).floor #=> 0
Rational(-3, 2).floor #=> -2
# decimal - 1 2 3 . 4 5 6
# ^ ^ ^ ^ ^ ^
# precision -3 -2 -1 0 +1 +2
Rational('-123.456').floor(+1).to_f #=> -123.5
Rational('-123.456').floor(-1) #=> -130
1439 1440 1441 1442 1443 |
# File 'rational.c', line 1439
static VALUE
nurat_floor_n(int argc, VALUE *argv, VALUE self)
{
return f_round_common(argc, argv, self, nurat_floor);
}
|