0

In this case, what does the percentage refers to?

int myInt = 27 % 10;  
myInt = 7;  

What does the % mean in this code?

Sled
  • 18,541
  • 27
  • 119
  • 168
user2570509
  • 59
  • 1
  • 6

4 Answers4

5

% means remainder, when 27 is divided by 10 leaves a remainder 7

EDIT: 

My 2 cents about all the discussion about difference between modulo & remainder

Take a % b

1. When both +ve, Modulo & Remainder are one and the same
2. When a is -ve, they are not the same

For example;

a = -10, b = 3

Remainder of -10 % 3 = -1

for Modulo, add a greater multiple of 3 to your 'a' and calculate the remainder.

-10 + 12 = 2

2 % 3 = 2 is your answer

Venkata Krishna
  • 14,926
  • 5
  • 42
  • 56
3

the % is modulus operator, not percentage. For percentage, you just do regular math. 50% is to multiply by .5... etc.

For future reference, the objective c mathematical operations are documented many places, including here.

Note the % is called "Modulo" operator.

PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56
1

% is a operator to find the remainder of a division.

jabaldonedo
  • 25,822
  • 8
  • 77
  • 77
0

The "%" in this code is called the modulus operator. This causes the processor to perform a division operation, and it returns the remainder of the division.

For example:

  • 8 % 10 = 8
  • 5 % 4 = 1
P4T4R
  • 101
  • 6