Rails number_to_currency 精度不起作用 - 这是一个错误吗?

发布于 2024-11-24 19:28:48 字数 378 浏览 5 评论 0原文

我试图使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝礼 2024-12-01 19:28:48

答案是检查区域配置文件中的以下设置:

  currency:
      format:
        strip_insignificant_zeros: false

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

  currency:
      format:
        strip_insignificant_zeros: false
假面具 2024-12-01 19:28:48

由于您似乎正在使用自定义区域设置,因此请尝试通过显式设置 number_to_currency 选项来强制执行您想要的行为:

number_to_currency(@purch.amount, :precision => 2)

您还可以在区域设置文件中为您的语言设置这些选项。看看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:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文