How to get the fractional part of a float in PHP

3 Answers

0 votes
$x = 748.9012;
    
$x = fmod($x, 1);

echo $x;




/*
run:

0.90120000000002

*/

 



answered Jun 13, 2023 by avibootz
0 votes
$x = 748.9012;

$x = $x - floor($x);

echo $x;





/*
run:

0.90120000000002

*/

 



answered Jun 13, 2023 by avibootz
0 votes
$x = 748.9012;

$x = $x - intval($x);

echo $x;





/*
run:

0.90120000000002

*/

 



answered Jun 13, 2023 by avibootz

Related questions

2 answers 230 views
3 answers 362 views
4 answers 243 views
2 answers 320 views
3 answers 2,151 views
1 answer 91 views
...