0

my questions are involve java script , is like user enters a number such like '12345' and the result will display '1 2 3 4 5'. I found solution on google but I don't understand this :

digit5 = number % 10;         
digit4 = (number % 100)/10;         
digit3 = (number % 1000)/100;         
digit2 = (number % 10000)/1000;         
digit1 = number / 10000;

could someone explain what is the meaning of {(number % 10); , (number % 100)/10; and so-on?

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Learning
  • 5
  • 4

2 Answers2

1

The % sign is the Quotient.

So in your example: The number is = 12345

so number % 1000;

is basically 12345 divide to 1000 which is 12 and 345/1000,

Now the % action will result with the remains Quotient which is 345,

Later you divided it by 100 which result with 3.45,

When you will use something li Math.floor() you will end with number 3

HatzavW
  • 560
  • 1
  • 4
  • 16
0

% Arithmetic Operators

Take a look at the arithmetic operators

Example - Name - Result

$a / $b - Division - Quotient of $a and $b.

$a % $b - Modulo - Remainder of $a divided by $b.

Community
  • 1
  • 1
Syno
  • 1,056
  • 10
  • 25