Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Rational#to_d

rat.to_d(precision) → bigdecimal

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 Kernel.BigDecimal.

See also #round #to_f #rationalize #to_i also in 3.2 · 3.1 · 3.0