Currently I am trying to solve a problem, where I am supposed to print the answer upto two decimal points without rounding off. I have used the below code for this purpose
import math
a=1.175 #value of a after some division
print(math.floor(a*100)/100)
Run Code Online (Sandbox Code Playgroud)
The output we get is:
1.17 #Notice value which has two decimal points & not rounded
Run Code Online (Sandbox Code Playgroud)
但当我尝试打印一个可整除的数字时,真正的问题就开始了,小数点后只显示一个零。我使用了与上面相同的代码,但现在
a=25/5 #Now a is perfectly divisible
print(math.floor(a*100)/100)
Run Code Online (Sandbox Code Playgroud)
现在显示的输出是
5.0 #Notice only one decimal place is printed
Run Code Online (Sandbox Code Playgroud)
必须采取什么措施来纠正这个错误?