Skip to content

Commit

Permalink
Merge pull request #27768 from kirs/am-decimal-cast
Browse files Browse the repository at this point in the history
Make BigDecimal casting consistent on different platforms
  • Loading branch information
guilleiguaran committed Jan 22, 2017
2 parents 20107ff + 7ec3040 commit b934f89
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion activemodel/lib/active_model/type/decimal.rb
Expand Up @@ -4,6 +4,7 @@ module ActiveModel
module Type module Type
class Decimal < Value # :nodoc: class Decimal < Value # :nodoc:
include Helpers::Numeric include Helpers::Numeric
BIGDECIMAL_PRECISION = 18


def type def type
:decimal :decimal
Expand All @@ -21,7 +22,7 @@ def cast_value(value)
when ::Float when ::Float
convert_float_to_big_decimal(value) convert_float_to_big_decimal(value)
when ::Numeric, ::String when ::Numeric, ::String
BigDecimal(value, precision.to_i) BigDecimal(value, precision || BIGDECIMAL_PRECISION)
else else
if value.respond_to?(:to_d) if value.respond_to?(:to_d)
value.to_d value.to_d
Expand Down

0 comments on commit b934f89

Please sign in to comment.