12
I am trying to use "reverse engineering" to understand what is the calculation done by the module (%
), but I’m not getting it and I wanted to understand and clarify, to make this part clear, before I go ahead and start doing exercises with it.
Then I saw this example:
If we do
23 % 10,
we divide 23 by 10 which equals 2 with 3 left over. So23 % 10
evaluates to3
.More examples:
17 % 5
evaluates to2
13 % 7
evaluates to6
In this first example he says that we divide 23 / 10
which is equal to 2
but in fact if we did this calculation would give 2,3
. So I thought, maybe what this means is:
23 % 10
equal to 2 with 3 outside, shall mean23 / 3
equal to2,3
, then this would be the reason equal to2
and3
outsider?!
But then when I applied this theory to the following examples, this theory did not apply... I also thought it might be the division of the number 23
by 2 that rounded would be 10 10 leaving the 3 out, but this theory would also have no logic because otherwise it would be 23 % 2
instead of 23 % 10
.
Warning: this truncation function is part of ES6 and not available on
Math
in any browser.– bfavaretto
Yeah, good warning. in that case it was more to demonstrate the functioning, no one will make that formula if they have the operator ready.
– Maniero