- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这里的上下文是我的问题:
我有一个零件表。一个零件是由一组 Material 制成的,我们称其为常量 Material 变量 z。所以这个表是一个由一组 Material 制成的零件表。此表中的每一行都是一个新部分。还有一列指示将从 1 套 Material 生产的零件数量。
如果我有:
var z = 1 //just some constant
var x = 5 //the amount of parts produced from a single set of materials
var y = 23 //the total amount of parts that have to be made
我知道用一组 Material 生产的零件数量,我也知道需要生产的零件数量。我生产的零件永远不会比需要的少,所以我知道 4 套 Material 可以生产 20 个零件,但我仍然少 3 个。如果我使用 5 套 Material ,我可以生产 25 个零件,剩下的 2 个零件。
我的问题是我尝试使用 mod 解决这个问题,但我在某处犯了错误
//Fun
const fun = async () => {
try {
let x = 23;
let y = 5;
const result = x/y
if(x%y == 0) {
console.log(x, ' divided by', y, ' has remainder of: ', x%y);
console.log(y, ' divided by', x, ' has remainder of: ', y%x);
}
else {
console.log(x, ' divided by', y, ' has remainder of: ', x%y);
console.log(y, ' divided by', x, ' has remainder of: ', y%x);
}
} catch (err) {
console.log(err.message);
}
}
因此,为了进一步增加清晰度,我总是想找到一个数可以除以某物的最大次数,如果它有余数,则记录余数。可能的解决方案是区分正余数还是负余数?感谢任何帮助,谢谢!!!
最佳答案
Math.floor( A/B )
,其中 A 是所需数量,B 是一组中的件数,将为您提供余数之前的除法数(因为除法是只是可以从 A 中减去 B 的次数,然后我们使用 Math.floor 向下舍入),(A%B)
将给出余数。
关于javascript - 如何返回数字 A 除以数字 B 的次数,直到它包含余数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71607724/
整数除法 / 和取模 % 运算在编程中经常一起使用,有时甚至在相同的操作数和后续行中使用。例如,下面的 C 函数是一个简单的函数,它将 2 个数字的 / 的结果与其 % 的结果相加,就是这样做的: i
我在我应该修复的程序中发现了一个函数,该函数的 mod函数定义: int mod(int a, int b) { int i = a%b; if(i 2 17 % -3 -> 2 -1
找出能被 1 到 N 的所有数整除且不留余数的最小数。由于数字可能非常大,我们将答案取模 1000000007。 我认为能被从 1 到 N 的所有数字整除的最小数字是 LCM(1..N)。 示例:对于
昨天我完成了 Chris Pine 的“学习编程”一书中的练习 (9.5)。它是老式罗马数字转换器的整数。 我是这样做的: def old_roman_numeral number roman
在 x64/sse 上使用矢量指令计算 x % M 的最佳/最快方法是什么? (% 我的意思是模数/余数)。 我找不到 packed mod 的任何操作码,所以我认为我能做的最好的事情是将 int 提
在 C# 中,是否有 C99/IEEE 754 的 remainder() 的完全等价物?功能? C# language specification says operator %(double x,
我刚看完 this topic (尤其是最后的评论)。 然后我想知道,为什么我们实际上需要这是给出余数。但似乎之前“在谷歌”上的人并不多...... 最佳答案 如果你正在寻找你想要它的原因,一个是所谓
我试图记住数学是如何计算出来的,以计算循环冗余检查中 XOR 算法的剩余部分,以验证网络消息的剩余位。 我不应该扔掉那本教科书。 这在代码中很容易完成,但是如何手工完成呢? 我知道它看起来有点像标准除
我为此做了很多搜索,但仍然不够幸运。 我知道默认情况下,Crystal Reports 中的 MOD/REMAINDER 函数适用于整数。 小数除以整数的余数有什么出路? 示例:2.454 mod 1
我为此做了很多搜索,但仍然不够幸运。 我知道默认情况下,Crystal Reports 中的 MOD/REMAINDER 函数适用于整数。 小数除以整数的余数有什么出路? 示例:2.454 mod 1
尝试将 rowCounter 除以 2 时如何在 ASP.NET Razor 中执行此操作?我收到红色下划线语法错误,提示“无法将类型‘long’隐式转换为‘bool’ long rowCounter
我试图使用 emu8086 工具将 (Unsigned) 8A32F4D5 除以 C9A5。我预计商为 AF73H,余数为 94B6H。编写以下代码后,我得到了正确的商,但余数变成了 0000h。我错
我试图使用 emu8086 工具将 (Unsigned) 8A32F4D5 除以 C9A5。我预计商为 AF73H,余数为 94B6H。编写以下代码后,我得到了正确的商,但余数变成了 0000h。我错
阅读@anton的答案在这个link我试着看看 remainder(x, y) 是否真的是 x-(round(x/y)*y)。 针对 x=5. 和 y=2. 的值运行代码。我得到了: printf("
我是一名优秀的程序员,十分优秀!