➕remainder (%)
remainder `r = a % b`, `r` has the same sign as `a`.
Last updated
Was this helpful?
remainder `r = a % b`, `r` has the same sign as `a`.
Last updated
Was this helpful?
Was this helpful?
JS ⟩ operator ⟩ arithmetic ⟩ remainder (%)
a
%
b
returns
a
, if a
= ±0 /b
= ±Infinity.
r
=
a
-
b
*
q
where:
q
is the integer such that:
r
has the same sign asa
, while being as close to 0 as possible.
// ⭐️ `a` decides the sign of the remainder
5 % 2 // 1
-5 % 2 // -1
⭐ remainder (%) and modulo are different❗ 👉 remainder vs. modulo vs. mod
% operator
works for numbers too.