为什么Math.floor返回零

Why does Math.floor return zero?

本文关键字:返回 floor Math 为什么      更新时间:2023-09-26

我想问一下为什么Math.floor方法返回零。这是我的代码:

var duration = 217;
var sec = Math.floor((duration / 1000) % 60);
var min = Math.floor((duration / (60 * 1000)) % 60);

怎么了?

var sec = Math.floor((duration / 1000) % 60);

(217/1000)%60=0.217

楼板值0.217为0。

的结果是(217/ 1000) % 600.217Math.floor()四舍五入到0

类似地,(217/ (60 * 1000)) % 600.0036166666666666665,其也向下舍入到0

因此,您看到了Math.floor()的正确行为,它"返回小于或等于一个数字的最大整数"。