floor

rat.floor â integerrat.floor(precision=0) â rational Instance Public methods Returns the truncated value (toward negative infinity). Rational(3).floor #=> 3 Rational(2, 3).floor #=> 0 Rational(-3, 2).floor #=> -1 decimal - 1 2 3 . 4 5 6 ^ ^ ^ ^ ^ ^ precision -3 -2 -1 0 +1 +2 '%f' % Rational('-123.456').floor(+1) #=> "-123.500000" '%f' % Rational('-123.456').floor(-1) #=> "-130.000

inspect

rat.inspect â string Instance Public methods Returns the value as a string for inspection. Rational(2).inspect #=> "(2/1)" Rational(-8, 6).inspect #=> "(-4/3)" Rational('1/2').inspect #=> "(1/2)"

numerator

rat.numerator â integer Instance Public methods Returns the numerator. Rational(7).numerator #=> 7 Rational(7, 1).numerator #=> 7 Rational(9, -4).numerator #=> -9 Rational(-2, -10).numerator #=> 1

quo

rat.quo(numeric) â numeric Instance Public methods Performs division. Rational(2, 3) / Rational(2, 3) #=> (1/1) Rational(900) / Rational(1) #=> (900/1) Rational(-2, 9) / Rational(-9, 2) #=> (4/81) Rational(9, 8) / 4 #=> (9/32) Rational(20, 9) / 9.8 #=> 0.22675736961451246

rationalize

rat.rationalize â selfrat.rationalize(eps) â rational Instance Public methods Returns a simpler approximation of the value if the optional argument eps is given (rat-|eps| <= result <= rat+|eps|), self otherwise. r = Rational(5033165, 16777216) r.rationalize #=> (5033165/16777216) r.rationalize(Rational('0.01')) #=> (3/10) r.rationalize(Rational('0.1')) #=> (1/3)

round

rat.round â integerrat.round(precision=0) â rational Instance Public methods 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

to_d

r.to_d(precision) â bigdecimal Instance Public methods Converts a Rational to a BigDecimal. The required precision parameter is used to determine the amount of significant digits for the result. See BigDecimal#div for more information, as it is used along with the denominator and the precision for parameters. r = (22/7.0).to_r # => (7077085128725065/2251799813685248) r.to_d(3) # => #<BigDecimal:1a44d08,'0.314E1',18(36)>

to_f

rat.to_f â float Instance Public methods Return the value as a float. Rational(2).to_f #=> 2.0 Rational(9, 4).to_f #=> 2.25 Rational(-3, 4).to_f #=> -0.75 Rational(20, 3).to_f #=> 6.666666666666667

to_i

rat.to_i â integer Instance Public methods Returns the truncated value as an integer. Equivalent to rat.truncate. Rational(2, 3).to_i #=> 0 Rational(3).to_i #=> 3 Rational(300.6).to_i #=> 300 Rational(98,71).to_i #=> 1 Rational(-30,2).to_i #=> -15

to_json

to_json(*) Instance Public methods