Permalink
Browse files

Merge pull request #27768 from kirs/am-decimal-cast

Make BigDecimal casting consistent on different platforms
  • Loading branch information...
guilleiguaran committed Jan 22, 2017
2 parents 20107ff + 7ec3040 commit b934f89fc3bac907e5bf49bff2b24e0d9cc41213
Showing with 2 additions and 1 deletion.
  1. +2 −1 activemodel/lib/active_model/type/decimal.rb
@@ -4,6 +4,7 @@ module ActiveModel
module Type
class Decimal < Value # :nodoc:
include Helpers::Numeric
BIGDECIMAL_PRECISION = 18
def type
:decimal
@@ -21,7 +22,7 @@ def cast_value(value)
when ::Float
convert_float_to_big_decimal(value)
when ::Numeric, ::String
BigDecimal(value, precision.to_i)
BigDecimal(value, precision || BIGDECIMAL_PRECISION)
else
if value.respond_to?(:to_d)
value.to_d

0 comments on commit b934f89

Please sign in to comment.