在您的特定用例中...您只需要在小数点后5位表示大约一米精度的纬度和经度,而度数只需要小数点前三位.Float(24) 或 decimal(8,5) 最适合您在 MSSQL 中的需求,并且在 C# 中使用 float 就足够了,您不需要 double.事实上,您的用户可能会感谢您四舍五入到小数点后 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. 解决方案 floatOr if you want to go old-school:realYou 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's float type is equivalent to the 64-bit double type in .NET. (My original answer from 2011 said there could be a slight difference in mantissa, but I've tested this in 2020 and they appear to be 100% compatible in their binary representation of both very small and very large numbers -- see https://dotnetfiddle.net/wLX5Ox for my test).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. 这篇关于什么代表sql server中的double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 02:28