What represents a double in sql server?

2019-01-03 23:52发布

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.

14条回答
迷人小祖宗
2楼-- · 2019-01-03 23:55

As most others have noted, float is the correct answer. See Microsoft's documentation on SQL Server - CLR datatype mapping for more information.

查看更多
再贱就再见
3楼-- · 2019-01-03 23:58

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...

查看更多
beautiful°
4楼-- · 2019-01-03 23:58

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 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

查看更多
\"骚年 ilove
5楼-- · 2019-01-03 23:59

You should map it to FLOAT(53)- that's what LINQ to SQL does.

查看更多
乱世女痞
6楼-- · 2019-01-04 00:04

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 -> "."

查看更多
做个烂人
7楼-- · 2019-01-04 00:10

Here are the CLR datatype mappings to SQL Server: http://msdn.microsoft.com/en-us/library/system.data.sqldbtype.aspx

查看更多
登录 后发表回答