在Rails控制台中将Big Decimal转换为String [英] Convert Big Decimal to String in Rails Console
本文介绍了在Rails控制台中将Big Decimal转换为String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让控制台打印出所有位置价目表价格的总和。
I am trying to get my console to print out a summation of all my Locations rate card pricing.
我试图通过控制台完成此任务,但得到结果是一个BigDecimal。坚持如何将结果转换为清晰的字符串或整数。
I am trying to complete this task through the console but getting a BigDecimal as the result. Stuck on how to convert this result into a legible string or integer.
结果:
Location.pluck(:rate_card).sum
=> "#<BigDecimal:7f7cf347edd0,'0.3091675E6',18(36)>"
在位置索引中,为了查看美元金额,我将其设置为:
In my Location 'index', to be able to see a dollar amount, I have this setup as:
<%= number_to_currency(location.rate_card, :precision => 2) %>
TIA
推荐答案
Location.each do |e|
puts e.rate_card.to_s.to_f.round(2)
end
这篇关于在Rails控制台中将Big Decimal转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文