为什么0.86%1不为零而是0.86,因为0.86/1给出余数为0?

Lor*_*iel 0 javascript math modulo

如果模数(%)与正数的"余数(r)"相同,那么为什么"0.86%1"结果为"0.86"而不是"0",因为"0.86/1 = 0.86",余数为0.

我已经看到了其他问题,但没有一个问题解决了1个条件下的模型.我能够理解这一点的唯一方法是认为0.86小于1,因此不能除以1,因此返回0.86作为余数.

use*_*ica 5

你说

"0.86/1 = 0.86",余数= 0.

好吧,只有在5/2 = 2.5且余数为0的意义上,很清楚这有什么不对,对吧?

当我们谈论剩余时,商必须是整数.它不能是2.5或0.86.如果你尽可能多地从除数中除去除数的倍数,剩下的就是余数.对于5/2,我们有

5-2 = 3
3-2 = 1
2>1, so we can't subtract any more, and the remainder is 1
Run Code Online (Sandbox Code Playgroud)

对于0.86/1,我们有

1>0.86, so we can't subtract any copies of 1 from 0.86, and the remainder is 0.86
Run Code Online (Sandbox Code Playgroud)