找到浮点数的除法余数Python

huangapple go评论53阅读模式
英文:

Find the division remainder of a float number Python

问题

找到浮点数的除法余数Python

为什么 0.03 除以 0.01,余数是 0.01,而不是零?

我尝试 0.3 % 0.1,结果是 0.1。对于 3 % 1,结果是零。太奇怪了。

英文:

找到浮点数的除法余数Python

Why 0.03 divide by 0.01, the reminder is 0.01, not zero??

I try 0.3 % 0.1, the result is 0.1. For 3 % 1, the result is zero. Crazy.

答案1

得分: 1

使用 remainder 可以避免这个错误,如下所示。

from math import remainder
remainder(0.03, 0.01)
英文:

Use remainder can avoid this error, as shown below.

from math import remainder
remainder(0.03,0.01)

huangapple
  • 本文由 发表于 2023年2月14日 22:03:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448952.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定