Adding floats does not yield a correct result
问题 Imagine the following situation. Amounts are added to a total in a loop: float total = 0; float[] amounts = new float[]{...}; foreach(float amount in amounts) { total += amount; } total , as wel as all the amount s are written to a database. When I calculate SUM(amount) in SQL, it results in a value that differs from total . Moreover, when I do the same calculation in C#, but this time adding the amounts to a value of type double, double total = 0; //the rest of the code is the same as above