Problem Storing Latitude and Longitude values in MySQL database

前端 未结 7 848
逝去的感伤
逝去的感伤 2020-12-24 03:19

I want to store the values of latitude and longitude fetched from Google Maps GeoCoding API in a MySQL database. The values are in float format.

12.92

7条回答
  •  天涯浪人
    2020-12-24 04:05

    You need to use decimal if you don't want the numbers to be approximated.

    Fixed-Point (Exact-Value) Types

    The DECIMAL and NUMERIC types store exact numeric data values. These types are used when it is important to preserve exact precision, for example with monetary data.

    And now the "here you go" answer:

    Use DECIMAL(10,7). Where 10 is the total number of digits in the number and 7 is the number of digits after the .. (This means that before the dot will be 3 digits.)

    Adjust these numbers as needed. Also please take a look at the manual entry I linked earlier in the answer.

提交回复
热议问题