Could anyone please tell me why this happens,
$a = 0.000022
echo $a // 2.2E-5
What I want to see is 0.000022
not 2.2E-5
PHP Floats A float is a number with a decimal point or a number in exponential form. 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats. The float data type can commonly store a value up to 1.7976931348623E+308 (platform dependent), and have a maximum precision of 14 digits.
Because superscripted exponents like 107 cannot always be conveniently displayed, the letter E or e is often used to represent times ten raised to the power of (which would be written as "x 10b") and is followed by the value of the exponent.
The is_float() function checks whether a variable is of type float or not. This function returns true (1) if the variable is of type float, otherwise it returns false.
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.
use number_format()
function
echo number_format($a,6,'.',',');
the result would be 0.000022
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With