I have a couple of properties in C#
which are double
and I want to store these in a table in SQL Server, but noticed there is no double
type, so what is best to use, decimal
or float
?
This will store latitude and longitude values, so I need the most accurate precision.
Thanks for the responses so far.
This question is related to
c#
sql
sql-server
sql-server-2005
tsql
You should map it to FLOAT(53)- that's what LINQ to SQL does.
It sounds like you can pick and choose. If you pick float, you may lose 11 digits of precision. If that's acceptable, go for it -- apparently the Linq designers thought this to be a good tradeoff.
However, if your application needs those extra digits, use decimal. Decimal (implemented correctly) is way more accurate than a float anyway -- no messy translation from base 10 to base 2 and back.
float is the closest equivalent.
For Lat/Long as OP mentioned.
A metre is 1/40,000,000 of the latitude, 1 second is around 30 metres. Float/double give you 15 significant figures. With some quick and dodgy mental arithmetic... the rounding/approximation errors would be the about the length of this fill stop -> "."
A Float
represents double
in SQL server. You can find a proof from the coding in C# in visual studio. Here I have declared Overtime
as a Float
in SQL server and in C#. Thus I am able to convert
int diff=4;
attendance.OverTime = Convert.ToDouble(diff);
Here OverTime
is declared float type
For SQL Sever:
Decimal Type is 128 bit signed number Float is a 64 bit signed number.
The real answer is Float, I was incorrect about decimal.
The reason is if you use a decimal you will never fill 64 bit of the decimal type.
Although decimal won't give you an error if you try to use a int type.
Here is a nice reference chart of the types.
float
in SQL Server actually has [edit:almost] the precision of a "double" (in a C# sense).
float
is a synonym for float(53)
. 53 is the bits of the mantissa.
.NET double
uses 54 bits for the mantissa.
Source: Stackoverflow.com