I’m using SQL Server and in one of the tables I have a nullable float column. When I look at that value in Microsoft SQL Server Management Studio I have a value in one of the records as 1.3. I also have a client app that gets data from the database via Entity Framework (EF) and it has a corresponding nullable double (double?) property for that column. Now when I get a value from the database it has 1.2999999523162842 values in it.
All these records (more than 1 million) will be used in interpolation, extrapolation, calculation and any smallest deviation becomes a significant value. So all values on the client side have to match values in the database.
I can’t round on the client side to the first decimal number, because in the database there are values with 2, 3, 4, or more decimal points.
My question is how can I make sure that all values in the database will be the same values on the client after loading them from database via EF?
Isn’t
floata binary floating point value in SQL Server? If so, your value isn’t really 1.3, as that isn’t exactly representable in binary floating point. Options:decimalon the .NET side as well.Using my DoubleConverter, it looks like the closest
doublevalue to 1.3 is actually 1.3000000000000000444089209850062616169452667236328125 – so I’m not sure why you’d be getting the value you’re actually seeing. The closestfloatvalue is 1.2999999523162841796875, which sounds like it’s what you’re getting. So it’s as if your value in the database is being converted as a 32-bit floating point number instead of a 64-bit one.Is your database field actually something like
FLOAT(23)? If so, that corresponds with a .NETfloatinstead ofdouble. That would explain things.