class Rational
available on Rational objects.
When you require BigDecimal in your application, this method will be
BigDecimal extends the native Rational class to provide the #to_d method.
def to_d(precision)
r.to_d(3)
# => (7077085128725065/2251799813685248)
r = (22/7.0).to_r
parameters.
as it is used along with the #denominator and the +precision+ for
significant digits for the result. See BigDecimal#div for more information,
The required +precision+ parameter is used to determine the amount of
Converts a Rational to a BigDecimal.
r.to_d(precision) -> bigdecimal
call-seq:
def to_d(precision) if precision <= 0 raise ArgumentError, "negative precision" end num = self.numerator BigDecimal(num).div(self.denominator, precision) end