method
cast_value
v5.1.7 -
Show latest stable
- Class:
ActiveModel::Type::Decimal
cast_value(value)private
No documentation available.
# File activemodel/lib/active_model/type/decimal.rb, line 19
def cast_value(value)
casted_value = case value
when ::Float
convert_float_to_big_decimal(value)
when ::Numeric
BigDecimal(value, precision || BIGDECIMAL_PRECISION)
when ::String
begin
value.to_d
rescue ArgumentError
BigDecimal(0)
end
else
if value.respond_to?(:to_d)
value.to_d
else
cast_value(value.to_s)
end
end
apply_scale(casted_value)
end