vbaexcel

How to sum cell values in two decimal places


One of my columns is formatted as currency until 2 decimal places. When i use add the values up using SUM formula or + , the total is different from what i manually calculated based on two decimal places. E.g. if 1.16 + 2.25 = 3.41, excel will give me a slightly different value. I am guessing this is internal rounding from excel. How to overcome this? I only want to add exactly at two decimal places. Thanks


Solution

  • While formatting the text as dollars and cents displays the values to two digits, it really does not modify the underlying number. In other words, a number like 1.16287 will display formatted as $1.16 but will still be 1.16287. You can check the underlying amount to verify this by setting a cell with a general format to the be equal to this value. Likewise a number 2.2498 will display as $2.25. The currency formatting will round the value when displaying it. I suggest you change each resulting formula computation in the column containing the currency to be a rounded number to two decimal places. For example if it is =A1*B1 make it =ROUND(A1*B1,2). This will preserve both the existing amounts in that column and result in a sum which does not show the issue you describe. Truncating will work similarly but does not round the result in the same way that the currency format works, so while it may work for the particular example you posted, you may have different results than what you are expecting with other values if this spreadsheet is used for other amounts.

    I think your scenario is like the situation in A7:D11 in the attached picture. While truncating fixes that, it would not give you the correct result in the scenario shown in A1:D5. Rounding the number in the formatted cell should give you the correct sum in either scenario.

    enter image description here