Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Big Decimal to String in Rails Console

I am trying to get my console to print out a summation of all my Locations rate card pricing.

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.

Results:

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

like image 494
RubyNewbie Avatar asked Jan 07 '14 19:01

RubyNewbie


1 Answers

Location.each do |e|
  puts e.rate_card.to_s.to_f.round(2)
end
like image 144
Darby Avatar answered Sep 22 '22 09:09

Darby