在 Rails 控制台中将大十进制转换为字符串 [英] Convert Big Decimal to String in Rails Console

查看:12
本文介绍了在 Rails 控制台中将大十进制转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图让我的控制台打印出我所有位置价目表定价的总和.

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 控制台中将大十进制转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆