什么再presents SQL Server中的双? [英] What represents a double in sql server?

查看:130
本文介绍了什么再presents SQL Server中的双?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个属性 C#这是双击,我想将这些存储在一个表SQL Server中,但发现没有双击的类型,所以什么是最好的使用,小数浮动

这将存储经纬度值,所以我需要最准确的precision。

由于迄今的回应。


解决方案

 浮动

或者,如果你想要去的老派:

 

您也可以使用float(53),但它意味着同样的事情浮动。

(真实等同于浮动(24),而不是浮动/浮动(53)。)

十进制(X,Y) SQL服务器类型是当你想要的确切的十进制数,而不是浮点(可以是近似值)。这是相到C#小数数据类型,这更像一个128位浮点数。

MSSQL的浮动没有的究竟的同一precision为64位的双击键入.NET(中略有差异尾数IIRC),但它是一个足够接近符合大多数用途。

为了让事情更混乱,一个漂浮在C#中只有32位,所以它会在SQL更等同于真正的/浮点(24)输入MSSQL比浮动/浮动(53)。

在您的具体使用案例...
所有你需要的是小数点后5位约一米precision内重新present纬度和经度,你只需要最多3位数字的小数点学位前的。 FLOAT(24)或十进制(8,5),将最适合在MSSQL您的需求,并在C#中使用浮动是不够好,你并不需要加倍。事实上,你的用户可能会感谢你四舍五入到5位小数,而不是一堆无关紧要的数字凑凑热闹到来。

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.

解决方案

float

Or if you want to go old-school:

real

You can also use float(53), but it means the same thing as float.

("real" is equivalent to float(24), not float/float(53).)

The decimal(x,y) SQL Server type is for when you want exact decimal numbers rather than floating point (which can be approximations). This is in contrast to the C# "decimal" data type, which is more like a 128-bit floating point number.

MSSQL float does not have exactly the same precision as the 64-bit double type in .NET (slight difference in mantissa IIRC), but it's a close enough match most uses.

To make things more confusing, a "float" in C# is only 32-bit, so it would be more equivalent in SQL to the real/float(24) type in MSSQL than float/float(53).

In your specific use case... All you need is 5 places after the decimal point to represent latitude and longitude within about one-meter precision, and you only need up to three digits before the decimal point for the degrees. Float(24) or decimal(8,5) will best fit your needs in MSSQL, and using float in C# is good enough, you don't need double. In fact, your users will probably thank you for rounding to 5 decimal places rather than having a bunch of insignificant digits coming along for the ride.

这篇关于什么再presents SQL Server中的双?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆