dongxiezhi0590 2018-07-13 09:03
浏览 336

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.

  • 写回答

1条回答 默认 最新

  • duanjiao5082 2018-07-13 09:42
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度