0

I'm using entity framework and mysql as a backend.

I have an entity that has lat and long which are of type float.

Let's say the values are lat:45.50818 and long:-73.55409

after the insert in the db the values in the DB are lat:45.508183 and long:-73.554092

in the db the type is float (10,6)

where does the extra 3 and 2 coming from?

Also when I query the db my entity contains the correct lat/long ...

Any help is appreciated,

Thank you

pdiddy
  • 6,217
  • 10
  • 50
  • 111

1 Answers1

2

you should use decimal data type instead

decimal(10,6)

Flaoting point numbers are only approximate numbers. Defining float(10,6)means only that you can store that precision but the number may be inaccurate after that precision. Fixed-point numbers don't have that problem.

juergen d
  • 201,996
  • 37
  • 293
  • 362
  • will try, but do you know the reason behind this behavior? – pdiddy Jun 02 '12 at 15:26
  • 1
    Note that `decimal` is a floating point type too. It's not really that floating point numbers are "only approximate numbers" - it's that they can't represent *every possible number* exactly, and in particular *binary* floating point numbers can't represent some "simple" numbers exactly, such as 0.1. – Jon Skeet Jun 02 '12 at 15:28
  • 1
    Put Simply, Decimal values are precise. Float is not. Float allows for imprecision and faster calculations when precision isn't important. http://stackoverflow.com/questions/618535/what-is-the-difference-between-decimal-float-and-double-in-c – xQbert Jun 02 '12 at 15:31