Convert float to string in php? Convert float to string in php? php php

Convert float to string in php?


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.