lib/virtus/coercion/string.rb in virtus-0.5.1 vs lib/virtus/coercion/string.rb in virtus-0.5.2

- old
+ new

@@ -131,13 +131,17 @@ # # @return [Integer] # # @api public def self.to_integer(value) - # coerce to a Float first to evaluate scientific notation (if any) - # that may change the integer part, then convert to an integer - coerced = to_float(value) - ::Float === coerced ? coerced.to_i : coerced + if value =~ /\A#{INTEGER_REGEXP}\z/ + value.to_i + else + # coerce to a Float first to evaluate scientific notation (if any) + # that may change the integer part, then convert to an integer + coerced = to_float(value) + ::Float === coerced ? coerced.to_i : coerced + end end # Coerce value to float # # @example