I am working on an app that deals with ecommerce sales orders. We use the money-rails gem.
Orders are imported from another system which may occasionally have numbers with partial cents. For example:
Order Line Item
quantity = 5
unit price = 1.29
discount = 0.064
In our database, our columns are integers and amounts are stored as cents. Unfortunately, when we calculate the subtotal of a line item using the imported values stored in our database, we end up getting rounded numbers because the integer column only stores whole numbers.
In the above example, we would calculate a subtotal of 5 x (129 - 6) which equals $6.15 but in reality it should really be 5 x (129 - 6.4) which equals $6.13.
When using the money-rails gem, what would be the best practice avoid these types of rounding errors? Should we convert our columns from integer to decimal? Or is there another method that works better?