I use entity framework which generates code to read the DB. But it seems that a in DB stored FLOAT value 999,999,999 will be read as 1E9.
How to enable that the autoge开发者_StackOverflow中文版nerated code returns the correct value 999,999,999 and not 1E9?
I think the problem has nothing to do with EF or SQL Server. Even in .NET you cannot store a value of 999,999,999 in a float:
float x = 999999999;
x will have the value 1E+9. The precision of float
isn't high enough to store this value (only 7 digits mantissa). A float
property in a class is mapped to a real
column in SQL Server (which has the same precision).
The only solution is to use double
or decimal
in your class (double maps to float
in SQL Server which has 15 digits precision).
Perhaps you have type float
in SQL Server which allows you to store the value 999,999,999 and also float
as the property type of your class which is unfortunately another type. It's confusing, yes: float
in SQL Server corresponds to double
in .NET (NOT TO float
!)
Usually 1E9 is a display and not the value. That is, whatever control you're using to display it is truncating it to 1E9 (like Excel does if you shrink the cell.)
Are you sure that it's the actual value returned from the DB?
精彩评论