Neeraj Kumar
2006-May-08 04:08 UTC
[Rails] How to check if a given string is a valid float value or not
I can''t use active record or anything. I need to validate inside the controller. I thought I could use to_f in the string method. The problem is that for a value of 1.3fsfs it returns 1.0 . I thought it would be consistently 0.0 . I can get a hack around it but looking for an elegant solution. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060508/1cb18804/attachment.html
Jake Janovetz
2006-May-08 04:24 UTC
[Rails] Re: How to check if a given string is a valid float value or
Neeraj Kumar wrote:> I can''t use active record or anything. I need to validate inside the > controller. I thought I could use to_f in the string method. The > problem is > that for a value of 1.3fsfs it returns 1.0 . I thought it would be > consistently 0.0 . I can get a hack around it but looking for an elegant > solution. > > Thanks.I think ActiveRecord just tries to call Kernel.Float(string) to see if it can be converted properly. This is also how I do it for a similar validation. Jake -- Posted via http://www.ruby-forum.com/.