MSSQL float data problem
Hello,
I am connecting to MSSQL through ODBC using regular SQL commands (SQLAllocHandle, SQLConnect, SQLFetch). Sometimes when I retrieve float data from the server it gets corrupted. For instance, instead of 59.457443 I will actually get 59.45744299999998. The value that is stored in the database is 59.457443 and it is stored as a float. The code I use to retrieve the data worked OK with an Access database, the problem only appeared after switching to MSSQL. Does anybody know if it's a configuration issue? Any help would be greatly appreciated.
EoF
[605 byte] By [
EoF] at [2008-1-10]
My guess is that it's being rounded to the nearest milliononth but storing the entire value. Once you relocate the value, the original value is returned.
If you are looking for the desired value, you'll have manually round the value in your code.
Adam
Thank you for your reply. I don't think that is the problem as I did some further testing. If I don't use ODBC to connect to the Server but System.Data.SqlClient, I get the correct value, so I guess it is an ODBC problem.
EoF at 2007-10-3 >

EoF wrote: |
Thank you for your reply. I don't think that is the problem as I did some further testing. If I don't use ODBC to connect to the Server but System.Data.SqlClient, I get the correct value, so I guess it is an ODBC problem.
| |
As I suspected, ODBC may round floats when using SQL Server.
Please read the following article from Microsoft:
http://support.microsoft.com/kb/116332
Adam