Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Integer Cents or Decimal for Accounting Amounts?

I'm working on a rails application with Postgres and ActiveRecord that is keeping track of payments and transaction fees (which are based on percentages).

Currently I'm using BigDecimal (and decimal columns in ActiveRecord) to keep track of the values of these transactions, but dealing with rounding has been frustrating. (for example how 8.05 - 1.0 ==> 7.050000000000001)

Does it make sense to continue using decimal columns for dollar amounts? Or should I switch to storing everything in integer value cents so I don't need to deal with rounding issues.

An important note is that none of my transactions (as of now) are worth fractional cents.

What are the pros and cons of each approach?

like image 436
Cyrus Avatar asked Jun 04 '13 23:06

Cyrus


Video Answer


1 Answers

There are a number of possible strategies for dealing with currency in Rails,

Such as What is the best method of handling currency/money?

like image 142
muttonlamb Avatar answered Sep 19 '22 18:09

muttonlamb