Hi all,
I’m working on a financial app, and have set up some columns in my
tables as decimals with precision => 8 and scale => 2. My migration
looks like:
change_column :lineitems, :price, :decimal, :precision =>
8, :scale => 2
change_column :payments, :amount, :decimal, :precision =>
8, :scale => 2
I’ve run the migration and restarted the server. I also looked at the
Mysql tables to verify that the migration ran correctly, and the
fields look like they’re set up right ( DECIMAL(8,2) ).
The problem is that when I access these columns in the console, they
show up as Bigdecimal and it’s messing up my calculations. Here’s
what it looks like from the rails console:
Lineitem.find(34).price
=> #BigDecimal:31e4c74,‘0.3E4’,4(12)Payment.find(23).amount
=> #BigDecimal:31b8480,‘0.4125E4’,4(12)
What’s going on here? How do I get Rails to recognize that these are
decimal/currency amounts???