1
There are several questions related to this question, but always with integers.
For example:
<?php
function evenOdd($number){
$conta = $number / 2;
$resto = $number % 2;
if($resto == 0.0)
echo $conta.' - Par';
else
echo $conta.' - Ímpar';
}
evenOdd(11.8);
echo ' | ';
evenOdd(10.8);
echo ' | ';
evenOdd(5.075);
echo ' | ';
evenOdd(4.39);
What is the essence of whether it is even or odd ?
I do not know if I understood your doubt well, but to identify if it is even or odd we always divide the value by two and check the rest of this division. Example: 5/2 = 2 and 1 remains, so it is considered odd. 8/2 = 4 and 0 remains so it is even
– Wagner Soares
@Wagnersoares I think you really don’t understand. He meant for decimal numbers (fractionated). From what I’m reading on Wikipedia the concept of "even" or "odd" only applies to integer numerals. Now I don’t know if it’s true.
– Wallace Maxters
True, decimals are not classified as even or odd. An even number is an integer in the form n = 2 k, where k is an integer. Even numbers are therefore ..., -4, -2, 0, 2, 4, 6, 8, 10, ... An odd number is an integer in the form n = 2 k + 1, where k is an integer. Even numbers are therefore ..., -3, -1, 1, 3, 5, 7, ... 0,5 is not integer. Therefore, it is neither even nor odd.
– Wagner Soares
I closed it because at the end to check it’s the same as what has already been answered. I pointed out one that doesn’t say anything about integers, so any response and consideration about integers, decimals, float would fit there.
– Bacco
Why was this question denied ? It is even closed.
– Diego Souza