fmod stands for Floating Modulo. Modulo calculates the remainder of a division which is generally noted with the ‘%’ symbol. However, the general modulo expression expects both the divisor and dividend to be of integer type, this is a great limitation to such an important operation.
In PHP the fmod() function is used to calculate the Modulo of any division which may contain floats as both dividends and divisors.
float fmod ($dividend, $divisor)
Parameters: The function takes two parameters as follows:
- $dividend: This parameter takes a float which is to be divided.
- $divisor: This parameter takes a float which is to be used as a divisor.
Return Type: This function returns a Floating-point remainder of the division.
Input : $dividend = 2.7, $divisor = 1.3; Output : 0.1 Input : $dividend = -2.7, $divisor = 1.1; Output : -0.5
Below program illustrates the working of fmod() in PHP:
2.5 % 1.1 = 0.3 2.5 % 1.15 = 0.2 2.5 % 1.2 = 0.1
Important points to note:
- fmod() function returns Floating Point Modulo.
- fmod() is an approximation method and may not always return the accurate result.