Text.to_decimal
to_decimalscale
Group: Conversions
Documentation
Convert this Text to a Decimal.
Arguments
scale: the optional Decimal scale to use. SeeDecimal.set_scalefor more information about Decimal scales. If this argument is not used, the default scale is used.
Examples
Convert a Text to a Decimal.
d = "23.456".to_decimal
d == Decimal.new "23.456"
# => True
Convert a Text to a Decimal with an explicit scale.
d = "23.456".to_decimal scale=4
d == Decimal.new "23.456"
# => True
Get an error when using a scale that is too small.
"23.456".to_decimal scale=2
# => Arithmetic_Error
Errors
- If an explicit
scaleparameter is passed, and the scale is not large enough to represent the number exactly, anArithmetic_Erroris thrown.