Method: Rational#round
- Defined in:
- rational.c
#round ⇒ Integer #round(precision = 0) ⇒ Object
Returns the truncated value (toward the nearest integer; 0.5 => 1; -0.5 => -1).
Rational(3).round #=> 3
Rational(2, 3).round #=> 1
Rational(-3, 2).round #=> -2
decimal - 1 2 3 . 4 5 6
^ ^ ^ ^ ^ ^
precision -3 -2 -1 0 +1 +2
'%f' % Rational('-123.456').round(+1) #=> "-123.500000"
'%f' % Rational('-123.456').round(-1) #=> "-120.000000"
1406 1407 1408 1409 1410 |
# File 'rational.c', line 1406
static VALUE
nurat_round_n(int argc, VALUE *argv, VALUE self)
{
return f_round_common(argc, argv, self, nurat_round);
}
|