Skip to content

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

instance method

Complex#to_d

cmp.to_d → bigdecimal
cmp.to_d(precision) → bigdecimal

Returns the value as a BigDecimal.

The precision parameter is required for a rational complex number. This parameter is used to determine the number of significant digits for the result.

Example
require 'bigdecimal'
require 'bigdecimal/util'

Complex(0.1234567, 0).to_d(4)   # => 0.1235e0
Complex(Rational(22, 7), 0).to_d(3)   # => 0.314e1

See also Kernel.BigDecimal.

See also #to_c #to_f #rectangular #to_i also in 3.2 · 3.1 · 3.0