File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes mysql ::  I loose decimal places when i insert. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "mysql ::  I loose decimal places when i insert." Watch "mysql ::  I loose decimal places when i insert." New topic
Author

mysql :: I loose decimal places when i insert.

jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
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

Joined: Mar 28, 2007
Posts: 403
Hi,

Try using a column of type FLOAT rather than DOUBLE.

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




Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
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

Joined: Mar 28, 2007
Posts: 403
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

Joined: Oct 06, 2006
Posts: 127
thank you, decimal works fine.
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Cool
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mysql :: I loose decimal places when i insert.
 
Similar Threads
Double / Float Doubt.
"DecimalFormat"
Rounding problem
Percision problems with Double and Float numbers
How to find number of decimal places?