End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Rational#to_d
rat.to_d(precision) → bigdecimal
ext/bigdecimal/lib/bigdecimal/util.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/ext/bigdecimal/lib/bigdecimal/util.rb, line 128
def to_d(precision)
BigDecimal(self, precision)
end
Returns the value as a BigDecimal.
The required precision parameter is used to determine the number of significant digits for the result.
Example
require 'bigdecimal' require 'bigdecimal/util' Rational(22, 7).to_d(3) # => 0.314e1
See also BigDecimal::new.