Rails number_to_currency 精度不起作用 - 这是一个错误吗?
我试图使用 number_to_currency 来获取 Rails 3 中小数点后的两位数字,但我只能得到一位。我的数据库字段定义如下:
t.decimal "amount", :precision => 5, :scale => 2
在我的模板中,我有:
#{number_to_currency(@purch.amount)}
但结果是:PLN 34,7
在数据库中我可以清楚地看到:34.70
我想看到我的第二个零 - 这是一个功能还是我遗漏了什么?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案是检查区域配置文件中的以下设置:
The answer is to check the following setting in one's locale configuration file:
由于您似乎正在使用自定义区域设置,因此请尝试通过显式设置 number_to_currency 选项来强制执行您想要的行为:
您还可以在区域设置文件中为您的语言设置这些选项。看看http://guides.rubyonrails.org/i18n.html
Since you seem to be using a custom locale, try forcing the behavior you want by explicitly setting the options of number_to_currency:
You can also set these options in the locale file for your language. Take a look at http://guides.rubyonrails.org/i18n.html