Rails number_to_currency precision doesn't work - is it a bug?
I'm trying to use number_to_currency to get two digits after the decimal dot in Rails 3, but I can get only one. My DB field is defined like this:
t.decimal "amount", 开发者_StackOverflow :precision => 5, :scale => 2
In my template I have:
#{number_to_currency(@purch.amount)}
And yet as the result I get: PLN 34,7
In the DB I can clearly see: 34.70 I would like to see my second zero - is it a feature or am I missing something?Thanks!
The answer is to check the following setting in one's locale configuration file:
currency:
format:
strip_insignificant_zeros: false
Since you seem to be using a custom locale, try forcing the behavior you want by explicitly setting the options of number_to_currency:
number_to_currency(@purch.amount, :precision => 2)
You can also set these options in the locale file for your language. Take a look at http://guides.rubyonrails.org/i18n.html
精彩评论