Reputation: 3258
I am familiarizing myself with the data in a database I inherited. And the credit_amount
field is a decimal
which when pretty printed
returns something that looks like this:
<BigDecimal:6d28088,'0.0',9(18)>
I want to be able to read it, after I get the info using pluck
and then group_by
like this:
emails = Customer.pluck(:shop_id, :customer_id, :email, :credit_amount )
gemails = emails.group_by{ |shop_id, customer_id, email, credit_amount| customer_id }
pp gemails
Currently when this prints it looks like this:
"21274984473"=>
[[105,
"21274984473",
"[email protected]",
Mon, 28 Aug 2017 16:39:28 UTC +00:00,
#<BigDecimal:6d28088,'0.0',9(18)>],
[105,
"21274984473",
"[email protected]",
Wed, 02 Aug 2017 20:09:37 UTC +00:00,
#<BigDecimal:a0e1690,'0.0',9(18)>]],
Just trying to read that BigDecimal
number.. using to_f
has worked in the past, just not sure where to put that here?
Thanks
Upvotes: 0
Views: 125
Reputation: 30463
You could try this:
emails.each { |e| e[-1] = e[-1].to_f }
Upvotes: 3