Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mysql :: I loose decimal places when i insert.

 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i execute this sql:



my table only stores 3 decimal places :: 12.333, 12.444:

my table was created like so



I'd like to know why this happens, and how to fix it.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Try using a column of type FLOAT rather than DOUBLE.

Recreate your table like the one specified as under ::::



 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the same result, float or double.

lat:lng
4.7064595222473145:7.076568603515625

becomes

lat:lng
4.705:7.076
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MySQL docs mention "MySQL performs rounding when storing values" and I suspect this is the issue here. I duplicated your issue but changed the storage type to be FLOAT:

CREATE TABLE test (val, FLOAT);and the retrieved value did not matched the test value you provided.

My suggestion, for what it's worth, is use DECIMAL. I tried the same original test with:

CREATE TABLE test (val, DECIMAL(17,15));and it retrieved the value I gave it: 4.7064595222473145

Also, can you tell the version of mysql you are using ?
 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you, decimal works fine.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic