Decimal.to_float
to_float
Group: Conversions
Documentation
Convert this to a Float.
Examples
Convert Decimal 23.45 to a Float.
d = Decimal.new "23.45"
d.to_float
# => 23.45
Errors
- If the
Decimalis outside the representable range ofFloat(which is(-Double.MAX_VALUE, Double.MAX_VALUE), inclusive),+/-Infis returned, and anOut_Of_Rangewarning is attached. - If the conversion results in a loss of precision, a
Loss_Of_Numeric_Precisionwarning is attached.
Remarks
Precision Loss
While any Float can be precisely represented by a Decimal, not
every Decimal can be accurange represented by a Float, so this
conversion can lose precision. For this reason, converting a
Decimal to a Float always attaches a Loss_Of_Numeric_Precision
warning to the result.
Representable Values
If the Decimal is outside the representable range of Float (which
is (-Double.MAX_VALUE, Double.MAX_VALUE), inclusive), +/-Inf is
returned, and an Out_Of_Range warning is attached.