Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Integer#floor
floor(ndigits = 0) → integer
numeric.c
View on GitHub ↗
static VALUE
int_floor(int argc, VALUE* argv, VALUE num)
{
int ndigits;
if (!rb_check_arity(argc, 0, 1)) return num;
ndigits = NUM2INT(argv[0]);
if (ndigits >= 0) {
return num;
}
return rb_int_floor(num, ndigits);
}
Returns the largest number less than or equal to self with a precision of ndigits decimal digits.
When ndigits is negative, the returned value has at least ndigits.abs trailing zeros:
Example
555.floor(-1) # => 550 555.floor(-2) # => 500 -555.floor(-2) # => -600 555.floor(-3) # => 0
Returns self when ndigits is zero or positive.
Example
555.floor # => 555 555.floor(50) # => 555
Related: Integer#ceil.