On Fri, Jun 25, 2010 at 10:31, Rodrigo Rosenfeld Rosas <[email protected]> wrote: > What is the suggested path for dealing with number formats in Rails? > > Even if we set locale to pt-BR, for instance, if the user inputs a number > like '1.000,00' or '1000,00' in a form input, numerical validation will > yield an 'invalid_number' error, even though this is a valid format in > Brazil.
We use the same formats in Argentina, but I luckily I haven't yet been bitten by this. By sheer circumstance, I can't recall any times where I had a field that could be either a float or an integer that wasn't for money. So in my experience it's been easy to determine how to interpret the commas and periods, and cast the param string to an appropriate numeric value before passing it into the model. But if you have a field that can admit arbitrary numeric values in an app that needs to support multiple locales, then you could definitely get bitten because 100,001 and 100.001 could mean different things to different people. So perhaps it might make sense if you could add a local-sensitive `I18n.to_f` and `.to_i`, as well as a validator. Regards, Norman -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
