floating point precision in ruby on rails model validations

Posted by Chris Allison on Stack Overflow See other posts from Stack Overflow or by Chris Allison
Published on 2010-05-04T16:09:25Z Indexed on 2010/05/04 17:18 UTC
Read the original article Hit count: 340

Filed under:
|
|
|

Hello I am trying to validate a dollar amount using a regex: ^[0-9]+\.[0-9]{2}$

This works fine, but whenever a user submits the form and the dollar amount ends in 0(zero), ruby(or rails?) chops the 0 off. So 500.00 turns into 500.0 thus failing the regex validation.

Is there any way to make ruby/rails keep the format entered by the user, regardless of trailing zeros?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rails