Faced such a problem, I needed to find out how much 30% of the number 0.000175, I wrote "0.000175 / 100 * 30", and python says that it is 5.25e-05, but it is not 30%, if you do this through a calculator, it turns out 0.0000525. Either I am stupid and do not understand anything, or there is something wrong here.
- "5.25e-05" how much do you think it is? - Enikeyschik
- oneru.wikipedia.org/wiki/… - Enikeyschik
- "{0: 0.7f}". Format (0.000175 / 100 * 30) - nick_gabpe
3 answers
Print the value in a string through formatting with the specified number of decimal places (10 characters in this example)
print('{:.10f}'.format(0.000175 / 100 * 30)) # '0.0000525000' If you do not like the extra 0 because of the high accuracy, then you can remove them (with a crutch):
value = '{:.10f}'.format(0.000175 / 100 * 30) print(value) # '0.0000525000' print(value.rstrip('0')) # '0.0000525' Accuracy can be omitted, but then there may be rounding, as in the example below:
value = '{:f}'.format(0.000175 / 100 * 30) print(value) # '0.000053' With fractional, whole and familiar / need to be careful.
print 100/3 33 Refer to the decimal module or for example, you can replace the division sign with multiplication and degree, in this case it works correctly:
print 0.000175 *(100)**-1 * 30 # 5.25e-05 print '{:.7f}'.format(0.000175 *(100)**-1 * 30) # '0.0000525' - oneThe author has python3, so
print 100/3will not work, and in Python 3, the operator/performs division with the remainder, soprint(100/3) # 33.333333333333336- gil9red
5.25e-05 = 5.25 * 10 ^ -5 = 0.0000525
If you find it difficult to understand such a representation of numbers, then study the formatting. A source.
print( '%f!' % (0.000175 / 100 * 30) ) This way you can get the output in the form you need. But exploring the exponential record is also useful, with it your code will look more solid)