Is there a way for PHP to check if there is an number after the . in a variable?
for example: $x=4.5
and now i want PHP to check if its a round number or one with a number after the . like shown in $x
. I made a script where i want PHP to devide my Variale by 2 and then check if the variable is now round or has a decimal space.
while($dezimal !== 0) {
$dezimal/2;
//here is where i need to check if $dezimal is round or not
floor($dezimal);
}
CodePudding user response:
The modulo operator will tell you if a number is evenly divisible by another.
if ($dezimal % 2 === 0) {
// number divides evenly
} else {
// number has a remainder
}