Hello, I saw an issue on Github talking about ActiveModel validators Numercality validator only_integer is not reliable with decimal storage <https://github.com/rails/rails/issues/23224>.
The validator' default behaviour is checking the input with regular expression (/\A[+-]?\d+\z/) to see if input *matches an integer's format.* If the input is like "15.0", this validation would fail. But in some cases, you can only get "15.0", "15.00". For example, in a database storing all numbers using decimal(10,2). Should "15.0" or "15.00" be recognized as an integer? Or people would have to check it manually? I made a patch <https://github.com/rails/rails/pull/23238> to check if the *Actual Value* of a number is an integer, using BigDecimal#frac <http://ruby-doc.org/stdlib-2.3.0/libdoc/bigdecimal/rdoc/BigDecimal.html#method-i-frac> . As for the performance, I did a benchmark here: precise_integer_validator_benchmark <https://gist.github.com/southwolf/b6ae3c8ff82e959548ac>. A-million-times BigDecimal validation is about 2 seconds slower than RegEx validation on my MacBook Air. (2.6 vs 0.7), is it acceptable? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
