好吧,所以我做了一个简单的脚本,因为我很懒,只想添加我的公里数,以便所需的信息弹出。。。虽然我知道将变量更改为int()可以提供所需的正确信息,但如果没有它,我会收到一个奇怪的输出,我现在知道它是如何创建的了。。以下是脚本:
KMstandNu = 186645
KMsnaarhuisenterug = 18.7 * 2
KMnaarPascalenterug = 8.2 * 2
Wednesday2 = KMstandNu - KMsnaarhuisenterug
Wednesday1 = Wednesday2 - KMnaarPascalenterug
Tuesday2 = Wednesday1
Tuesday1 = Tuesday2 - KMnaarPascalenterug
print("22 oktober: " + str(Tuesday1) + " - " + str(Tuesday2))
print("23 oktober: " + str(Wednesday1) + " - " + str(Wednesday2))
输出:
22 oktober: 186574.80000000002 - 186591.2
23 oktober: 186591.2 - 186607.6
好吧,那么哪个聪明的头脑能帮我弄清楚为什么星期二1得到9 0和2落后于正确的数学
因为floating point precision。尝试使用十进制而不是浮点:
decimal Python docs
related question
输出:
22 oktober:186574.8000-186591.2000
23 oktober:186591.2000-186607.6000
相关问题 更多 >
编程相关推荐