php- floating point number shown in exponential form
use number_format()
function
echo number_format($a,6,'.',',');
the result would be 0.000022
Try this:
function f2s(float $f) {
$s = (string)$f;
if (!strpos($s,"E")) return $s;
list($be,$ae)= explode("E",$s);
$fs = "%.".(string)(strlen(explode(".",$be)[1])+(abs($ae)-1))."f";
return sprintf($fs,$f);
}
The exponential form is the internal one use by every (?) programming language (at least CPUs "sees" floats this way). Use sprintf()
to format the output
echo sprintf('%f', $a);
// or (if you want to limit the number of fractional digits to lets say 6
echo sprintf('%.6f', $a);
See Manual: sprintf()
about more information about the format parameter.