This article describes how to use Python to perform Division operations on decimals. The correct method is to convert it to a floating point. Otherwise, the correct result will never be obtained, for more information, see the following formula.
The Code is as follows:
A = 1
B = 2
C = 3
Print c * (a/B)
The running result is always 0. After repeated check and splitting, it is found that in Python, the first integer can only be an integer.
That is, the result of dividing a by B is always 0. You only need to change the number of a or B to a floating point number.
The Code is as follows:
A = 1
B = 2
C = 3
Print c * (a/float (B ))
Print c * (float (a)/B)
In this way, the correct result of Division B can be accurately calculated. Of course, if a is larger than B, and float is not required.
For example:
The Code is as follows:
A = 1
B = 2
C = 3
Print c/a #3
Print c/B #1
Print c/float (B) #1.5