round(p1)
Rounds flt 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 1.round(2) #=> 1.0 15.round(-1) #=> 20
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); }