2

I've created a database using the store locator tutorial on Google Code, which specifies that the fields to store marker coordinates be of type FLOAT(10,6). However, when I geocode certain points using Google's geocoder service I get some results with 14 decimal places. For example,

-70.07290899999998

The numbers are never more than 21 or less than -67 and always have between 1 and 14 digits after the decimal point.

How do I set this field in the database?

Keyslinger
  • 4,903
  • 7
  • 42
  • 50
  • MySQL should round for you. Per [the MySQL manual](http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html), a `FLOAT(7,4)` assigned a value of **999.00009** would be stored as **999.0001** – Brad Christie Dec 07 '11 at 18:56

2 Answers2

7

Don't use float; use fixed point. Float by nature is rough.

http://dev.mysql.com/doc/refman/5.0/en/fixed-point-types.html

3 before, 15 after DECIMAL(17,14)

xQbert
  • 34,733
  • 2
  • 41
  • 62
  • and for a better read: http://stackoverflow.com/questions/1074474/should-i-use-double-or-float simply put float sacrifices precision for speed. double is precise. But when dealing with math on such small or large scales often the precision is not needed. the flagged answer in the linked article really gets into the math theory (way over my head) – xQbert Dec 16 '11 at 12:10
3

I just use a DECIMAL column type, and six figures after the decimal point is more than accurate enough for locations.

Martin Bean
  • 38,379
  • 25
  • 128
  • 201