Em 25-06-2010 17:06, Norman Clarke escreveu:
Do you have any real use case where it would make sense to use
I18n.to_f(number, locale) instead of I18n.l(number, precision)?
Ok, either I don't understand something, am not communicating clearly,
or both. I think they are opposites. This is what I think they could
do:
# Given an instance of Float, format it to a string to display to
# Brazilian users.
I18n.localize(100000.01, :locale => :'pt-BR') #=> "100.000,01"
# Given input from a Brazilian user, cast to a Float.
I18n.to_f("100.001", :locale => :'pt-BR') #=> 100001.00
# Given an instance of Float, format it to a string to display to
# USA users.
I18n.localize(100000.01, :locale => :'en-US') #=> "100,000.01"
# Given input from a USA user, cast to a Float. Notice the value
# is different from what a Brazilian user would mean.
I18n.to_f("100.001", :locale => :'en-US') #=> 100.001
Ok, you're right, sorry, I didn't get it at first. Than, I would say
that to_f should be implemented as:
def I18n.to_f(value, locale=nil)
locale ||= I18n.locale # current locale if none was given
end
This would allow I18n.to_f('19.250,30') == 19250.3 ==
I18n.to_f('19,250.30', :en)
Why passing an option as the second parameter. What other options can
you think of?
Best regards,
Rodrigo.
--
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.