Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

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.

1 Answer

0 votes
by (40.4k points)

You can either use float or real. ‘float’ is used for the newer version of SQL server whereas, ‘real’ is used for the older version of SQL Server.

Float: You can use float or float(53) as their functionalities are the same.

Note: ‘real’ is equal to float(24) but not equal to float/float(53).

• In SQL Server, decimal(x, y) is used only when exact decimal numbers are needed not for the floating-point. But, in C# ‘decimal’ data is used as it’s 128-bit floating-point number. 

• MYSQL doesn’t have the same precision as the 64-bit double type in .NET

• In C#, ‘float’ is of 32-bit, hence it’s more equivalent in SQL to the float(24)/real data-type in MSSQL than the float(53)/float.

• In your case, to represent the latitude and longitude within one-meter precision you need 5 places after the decimal point and for the degrees you need up to 3 digits before the decimal point.

• In MSSQL, you can use float(24) or decimal(8,5) which will be best according to your needs. But, if you are working in C# then the float is good enough.

• For users, it’ll be more convenient to round up to 5 decimal places rather than a bunch of insignificant digits. 

Browse Categories

...