Instance method
# truncate
Returns self truncated (toward zero) to a precision of ndigits decimal digits.
How to use
Quick guide
Official content
Official how?
I scraped all this data from the official documentation. I created this site to make it easier for beginners and more pleasant for professionals to use Ruby.
Georgie boy
Creator of ruby-docs.org
Returns
self
truncated (toward zero) to a precision of ndigits
decimal digits.When
ndigits
is negative, the returned value has at least ndigits.abs
trailing zeros:555.truncate(-1) # => 550
555.truncate(-2) # => 500
-555.truncate(-2) # => -500
Returns
self
when ndigits
is zero or positive.555.truncate # => 555
555.truncate(50) # => 555
Related:
Integer#round
.
static VALUE
int_truncate(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_truncate(num, ndigits);
}
Was this page useful?
Leave your feedback
Please hit 'submit' to confirm your feedback.
Leave your feedback
Please hit 'submit' to confirm your feedback.