C # Floating Point calculation problems,
Let's take a look at our computing capabilities.
What is the value of 0.1 + 0.1 + 0.1-0.3?
You may ask this simple question: do you look down on me? It must be equal to 0.
If you calculate it directly, what if you use a computer?
It's time to witness the miracle. Read the Code:
Void Main () {var f = 0.1 + 0.1 + 0.1-0.3; Console. WriteLine ("f =={ 0}", f );}
Running result:
This is because of the accuracy of the computer, the lack of internal storage and computing accuracy in the computer, and other issues, I may not understand, however, you can use the following solution to solve:
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 );}
Running result:
This is the normal operation result.
La la !!!!