Convert Float To String In Php?


Answer :

echo number_format($float,0,'.','');


note: this is for integers, increase 0 for extra fractional digits



$float = 0.123;
$string = sprintf("%.3f", $float); // $string = "0.123";


It turns out json_decode by default casts large integers as floats. This option can be overwritten in the function call:



$json_array = json_decode($json_string, , , 1);


I'm basing this only on the main documentation, so please test and let me know if it works.



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable