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.
As most others have noted,
float
is the correct answer. See Microsoft's documentation on SQL Server - CLR datatype mapping for more information.Aren't there already mappings in the System.Data.Sql classes?
See: C#: SQL Server data types equivalents in .NET Framework.
Now, make mine a float...
Float
represents double inSQL server
. You can find a proof from the coding inC#
in visual studio. Here I have declared Overtime asFloat
in SQL server
and inC#
. Thus I am able to convertHere OverTime is declared
float type
You should map it to FLOAT(53)- that's what LINQ to SQL does.
float is the closest equivalent.
SqlDbType Enumeration
Edit:
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 -> "."
Here are the CLR datatype mappings to SQL Server: http://msdn.microsoft.com/en-us/library/system.data.sqldbtype.aspx