How to convert float to string in PHP

3 Answers

0 votes
$f = 23.5876;

$s = sprintf("%.4f", $f); 
    
echo $s;



  
/*
run:

23.5876

*/

 



answered Aug 30, 2019 by avibootz
0 votes
$f = 23.5876;
 
$s = (string)$f;
     
echo $s;



  
/*
run:

23.5876

*/

 



answered Sep 2, 2019 by avibootz
0 votes
$f = 23.5876;
 
$s = strval($f);
     
echo $s;



  
/*
run:

23.5876

*/

 



answered Sep 2, 2019 by avibootz

Related questions

2 answers 259 views
1 answer 154 views
154 views asked Aug 11, 2021 by avibootz
1 answer 201 views
201 views asked Apr 7, 2021 by avibootz
1 answer 210 views
210 views asked Apr 5, 2019 by avibootz
1 answer 221 views
...