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 242 views
3 answers 375 views
4 answers 251 views
2 answers 325 views
3 answers 2,162 views
1 answer 100 views
100 views asked Nov 16, 2022 by avibootz
...