Q:

Number representation discrepancies SQL Server 2012

I have a table in SQL Server 2012. One of the column is decimal (18,2) and is being used to store simple financial numbers.
In ASP Net program, rows are retrieved and based on some logic, some rows are added up (using variables of type double).  Based on the result, a logic is executed in which different loops are used : if the result is equal to, greater than or less than another variable.
The issue is that in some cases (and there is nothing in particular to point out what are those cases), the result is xxx.00000000000000000000000000000xxxx. (meaning at some billionth places, there are some numbers).  This forces the logic to go into a different loop when the other variable (with which a comparison is being made) is xxx.
It happened only in some cases but not sure what causes it to happen. For now, I have added Math.round to 2 decimal places. But making this change at every place will be a burden.
Any ideas what is causing this behavior?

A:

Floating point data types (e.g. .NET double, SQL Server float) are approximate because some values cannot be stored exactly according to the IEEE standard.  If you need exact decimal values, use Decimal in your .NET code.

