SQL adding random decimal points when getting real from DB to Double in C #

When I enter a double number from C # into the database, I use the real type in the database. When I check the value, this is exactly what I enter.

Now when I go to restore the value from the DB and save it in double C #, it adds random decimal values ​​at the end. The number in the database is the correct value I want, but the value in C # as a double is just random (sometimes higher sometimes lower than the actual value.)

ie

- Enter into the db 123.43 as a double to an sql real. - View the value in the DB, it exactly 123.43 - Get the value from the DB and store into a C# double, value in the double is now 123.4300000305176 

I tried changing the type to float, decimal, etc. in the database, but these types actually change the value when I put it in the database in the same format as above.

Any help on what's happening or how to fix it?

+4
source share
2 answers

You should probably use the decimal type. See What is a double in sql server? for further explanation.

+3
source

Try using Single if your type is DB real . Check here for data mappings http://msdn.microsoft.com/en-us/library/ms131092.aspx

0
source

All Articles