How to round a floating-point number to an integer in PHP

1 Answer

0 votes
$x = 9382.4;
$y = (int)round($x);
echo $y . "\n";

$x = 9382.5;
$y = (int)round($x);
echo $y . "\n";



/*
run:

9382
9383

*/

 



answered May 14, 2025 by avibootz
...