gpt4 book ai didi

JavaScript % (modulo) 给出负数的负数结果

转载 作者:IT老高 更新时间:2023-10-28 13:13:32 25 4
gpt4 key购买 nike

根据Google Calculator (-13) % 6451

根据 Javascript(见 JSBin),它是 -13

我该如何解决这个问题?

最佳答案

Number.prototype.mod = function (n) {
"use strict";
return ((this % n) + n) % n;
};

取自这篇文章:The JavaScript Modulo Bug

关于JavaScript % (modulo) 给出负数的负数结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4467539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com