3

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",              :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!

iRonin
  • 470
  • 4
  • 12

2 Answers2

3

The answer is to check the following setting in one's locale configuration file:

  currency:
      format:
        strip_insignificant_zeros: false
iRonin
  • 470
  • 4
  • 12
2

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

Thilo
  • 17,565
  • 5
  • 68
  • 84
  • 2
    I have tried :precision and got no juice as well, thank you however to pointing me to the locale options, I have found I had **:strip_insignificant_zeros** set to true which is the answer to my problem. Thank you! – iRonin Jul 21 '11 at 05:50