round(p1)
public
Rounds int to a given precision in decimal digits (default 0
digits).
Precision may be negative. Returns a
floating point number when ndigits is positive, self for
zero, and round down for negative.
1.round
1.round(2)
15.round(-1)
Show source
static VALUE
int_round(int argc, VALUE* argv, VALUE num)
{
VALUE n;
int ndigits;
if (argc == 0) return num;
rb_scan_args(argc, argv, "1", &n);
ndigits = NUM2INT(n);
if (ndigits > 0) {
return rb_Float(num);
}
if (ndigits == 0) {
return num;
}
return int_round_0(num, ndigits);
}