Handling international currency input in Ruby on Rails

前端 未结 5 1883
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 10:06

I have an application that handles currency inputs. However, if you\'re in the US, you might enter a number as 12,345.67; in France, it might be 12.345,67

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 10:49

    Using the translations for numbers in the built-in I18n should allow you to enter your prices in one format (1234.56) and then using I18n bringing them back out with number_to_currency to have them automatically printed out in the correct locale.

    Of course you'll have to set I18n.locale using a before_filter, check out the I18n guide, section 2.3.

提交回复
热议问题