Let 's look at a computational question and look at the arithmetic abilities of everyone.
0.1 +0.1 +0.1-0.3 equals a few?
People may say such a simple question, is not despise me? Must be equal to 0.
If the direct calculation is not a problem, but if you use a computer?
The time to witness a miracle is here, look at the code:
void Main () { var f = 0.1 +0.1 +0.1-0.3; Console.WriteLine ("F=={0}", f);}
Operation Result:
This is because of the problem of computer accuracy, in the computer's internal storage and operation of the lack of precision, and so on, I may not understand the explanation, however, you can use the following solution:
void Main () { //var f = 0.1 +0.1 +0.1-0.3; Console.WriteLine ("F=={0}", f); var f1 = new Decimal (0.1) + New Decimal (0.1) + New Decimal (0.1)-New decimal (0.3); Console.WriteLine ("F1 = = {0}", F1);}
Operation Result:
This is the result of the normal operation.
La La la!