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)
必须采取什么措施来纠正这个错误?
最近在MongoDB中做一个Mini项目。我试图使用该命令找出字段的不同值db.collections.distinct(<field>)。
上面的命令检索数组内给定字段的所有不同值。但由于我有 12k 个文档,所有值都没有显示在我的控制台中。
我搜索了互联网和文档,但无法得到正确的答案。