Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我理解 15 mod 5 = 0 因为除法没有余数。
但是为什么 15.5 mod 5 == 0 呢?剩下的不是0.5吗?
$time = "15.5"; $interval = 5.0; if($time % $interval == 0) echo "it's time!"; else echo "not time"; //Outputs: it's time!
来自PHP 文档:
模数的操作数在处理之前被转换为整数(通过去除小数部分)。
fmod如果要保留小数余数,请使用。(感谢Oli Charlesworth的链接,他不知道存在这样的功能。)
fmod