1. MySQL Question

I have a MySQL table with a double var. I have an sql statement which adds a value of "2.60106457" into the double item in the table. When I ask mysql to display what it has it displays 2.60106492042542. This only accurate to 6 places not the expected 16. Looks to me that mysql is wrong. Has anyone seen this or can explain?

new topic     » topic index » view message » categorize

2. Re: MySQL Question

Can you please give us a little more detail about the data in the table before you add the mentioned value and the server environment, including the version of MySQL. Also, are you using the mysql cli client or a GUI of some kind?

new topic     » goto parent     » topic index » view message » categorize

3. Re: MySQL Question

m_sabal said...

Can you please give us a little more detail about the data in the table before you add the mentioned value and the server environment, including the version of MySQL. Also, are you using the mysql cli client or a GUI of some kind?

I discovered that I was getting stars placed in the wrong place. I am updating what was in the my star database with coordinates RA and DEC that were from the Hipparcos database which had a lot of accuracy. The sql statement looks like this and both table entries are double precision;

sql = replace stars values RAnumeric, DECnumeric with values (2.60106457, 6.88336423)

than here is the code snipit

	a = execDirectODBC(dbId, sql) 
	if atom(a) then 
		odbcError(-a) 
		a = message_box("Can't find record " & openTbNames[t] & " " & recordKey&" to update.","",0) 
		abort(1) 
	else 
		-- OK 
	end if 
 

After this update I checked the table entry for the double var using mysql query and get the wrong value mentioned above. I am using MySql 4.00.22 and matt's odbc.e routines.It looks like what is in the database is single precision. Any suggestions?

new topic     » goto parent     » topic index » view message » categorize

4. Re: MySQL Question

My first suggestion is to upgrade MySQL to at least version 5.0 (version 5.6 is available), and to use the command line MySQL client for testing to rule out any other possible problems (such as a precision bug in your program, the version of the ODBC library, or the MySQLConnector ODBC driver). Could you run the query "SHOW COLUMNS IN stars" and post the results?

Also, replace is not a standard SQL query. The correct query should be like this:

sql = "update stars set RAnumeric = 2.60106457, DECnumeric = 6.88336423 where recordkey="&recordkey

new topic     » goto parent     » topic index » view message » categorize

5. Re: MySQL Question

gwalters said...

I have a MySQL table with a double var. I have an sql statement which adds a value of "2.60106457" into the double item in the table. When I ask mysql to display what it has it displays 2.60106492042542. This only accurate to 6 places not the expected 16. Looks to me that mysql is wrong. Has anyone seen this or can explain?

This is correct behaviour; the FLOAT (and DOUBLE, which is non-standard) types do not define precision- floating-point calculations are approximate. Notably, you can get into Deep Trouble using them to compute monetary values.
If you need a specific number of digits, you should use the DECIMAL type; e.g., DECIMAL(19,16) will give you +/- 999.9999999999999999.

Note that DECIMAL support is flawed in MySQL versions up through 5.0; make sure you are running the latest version (currently, 5.5.x).

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu