End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Float#to_d
float.to_d → bigdecimal
float.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 46
def to_d(precision=0)
BigDecimal(self, precision)
end
Returns the value of float as a BigDecimal. The precision parameter is used to determine the number of significant digits for the result (the default is Float::DIG).
Example
require 'bigdecimal' require 'bigdecimal/util' 0.5.to_d # => 0.5e0 1.234.to_d(2) # => 0.12e1
See also BigDecimal::new.