Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Numeric#truncate

() -> ::Integer
(::Integer ndigits) -> (::Integer | ::Numeric)
truncate(digits = 0) → integer or float

Returns self truncated (toward zero) to a precision of digits decimal digits.

Numeric implements this by converting self to a Float and invoking Float#truncate.

See also #to_int #zero? #to_c also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0