I have google coordinates that I have to change, but when I echo them, for example,
echo (string)28.9871692657471;
I get the result of
28.987169265747
" 1 " at the end disappears
echo (string) 28.9875984191895
" 5 " at the end disappears
I tried directly echoing it, without casting, but nothing has changed, the thing I want to do is to have this basic operation,
28.9875984191895 + 0.0000000000001 = 28.9875984191896
Is there something I am missing ? because I could not find anything about that when I search on the internet
Give this a try
echo bcadd("28.9875984191895", "0.0000000000001", 13);
The last parameter is the number of decimals to display
Floating point numbers are not accurate enough for that, but in any case the php.ini
setting precision
affects how many decimal digits are shown when a float is cast to a string, so try adjusting that (either edit the php.ini
file, or use ini_set("precision",50);
)
Per the PHP docs on floating point numbers:
So never trust floating number results to the last digit, and do not compare floating point numbers directly for equality. If higher precision is necessary, the arbitrary precision math functions and gmp functions are available.