I can not understand how percent work in php.

For example:

php:

1%13 = 1 13%13 = 0 

Calculator:

 1%13 = 0.13 13%13 = 1.69 

Please clarify what my problem is misunderstanding

  • 3
    % in php is the operator of the remainder of the division. And your problem is that you do not want to open the manual for pkhp and get acquainted with it. - u_mulder Nov.
  • one
    Welcome to ruSO! The% symbol in PHP does not mean a percentage of numbers. This is an operator whose result is the remainder of the division. - Dima Nov.

1 answer 1

how do percent work in php

In PHP, the same as in mathematics: 1% == 0.01

 echo 0.01 * 13; // 0.13 echo 0.13 * 13; // 1.69 

The % symbol looks similar to the Percentage key of any calculator, but in PHP it is a modulo operator. As a result, you get the integer remainder of the division:

 echo (2 % 2); // 0 echo (3 % 2); // 1 echo (4 % 2); // 0