7

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?

4

1 回答 1

3

在 Rails 中处理货币有多种可能的策略,

例如处理货币/金钱的最佳方法是什么?

于 2013-06-04T23:59:32.010 回答