How to get the first digit after the decimal point of a float number in PHP

2 Answers

0 votes
$f = 23.5876;
 
$s = sprintf("%.4f", $f); 
     
echo $s[strrpos($s, ".") + 1];



  
/*
run:

5

*/

 



answered Aug 31, 2019 by avibootz
0 votes
$f = 23.6876;
 
echo (int)(floor(abs($f) * 10)) % 10;



  
/*
run:

6

*/

 



answered Aug 31, 2019 by avibootz
...