Text.to_decimal
to_decimalscale
Group: Conversions
Documentation
Convert this Text
to a Decimal
.
Arguments
scale
: the optional Decimal scale to use. SeeDecimal.set_scale
for 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
! Error Conditions
- If an explicit `scale` parameter is passed, and the scale is not
large enough to represent the number exactly, an `Arithmetic_Error`
is thrown.
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