MySQL ST_AsGeoJSON返回的浮点数不是原始数据

I am using PHP to save a row in a database. One field is of the type geometry. I save a POINT with the coordinates 52.5219 and 13.4132.

When I retrieve the row, I use ST_AsGeoJSON. It returns me:

"geometry": {
    "type": "Point",
    "coordinates": [
        52.5219000000000022509993868879973888397216796875,                        
        13.413199999999999789679350215010344982147216796875
    ]
}

I want the results without the extra digits. This is only happening on my staging server. On my local server it returns the correct coordinates.

This is a common problem. you can read more about this from here: https://bugs.php.net/bug.php?id=41357

How it produces? When you subtract an integer number from a float number sometimes it will gives you this type of error. For example:

var_dump(214.16569 - 214);

var_dump(114.16569 - 114);

Solution:

There are several way to fix this issue. I use the below code to limit the digit after the decimal. To limit upto 4 digit:

$value = number_format($value, 4);

you can use the above code to format your data. It will show only 4 digit after the decimal.