Decimal rounding strategies in enterprise applications
        Posted  
        
            by Sapphire
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Sapphire
        
        
        
        Published on 2010-03-24T20:34:21Z
        Indexed on 
            2010/03/24
            20:43 UTC
        
        
        Read the original article
        Hit count: 288
        
Well, I am wondering about a thing with rounding decimals, and storing them in DB.
Problem is like this:
Let's say we have a customer and a invoice.
The invoice has total price of $100.495 (due to some discount percentage which is not integer number), but it is shown as $100.50 (when rounded, just for print on invoice). It is stored in the DB with the price of $100.495, which means that when customer makes a deposit of $100.50 it will have $0.005 extra on the account. If this is rounded, it will appear as $0, but after couple of invoices it would keep accumulating, which would appear wrong (although it actually is not).
What is best to do in this case. Store the value of $100.50, or leave everything as-is?
© Stack Overflow or respective owner