Re: MySQL Question

new topic     » goto parent     » topic index » view thread      » older message » newer message
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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu