I'm working on a very basic shopping cart system.
I have a table items
that has a column price
of type integer
.
I'm having trouble displaying the price value in my views for prices that include both Euros and cents. Am I missing something obvious as far as handling currency in the Rails framework is concerned?
Best Answer
You'll probably want to use a
DECIMAL
type in your database. In your migration, do something like this:In Rails, the
:decimal
type is returned asBigDecimal
, which is great for price calculation.If you insist on using integers, you will have to manually convert to and from
BigDecimal
s everywhere, which will probably just become a pain.As pointed out by mcl, to print the price, use: