Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float in Database to ? in .NET

If you have a float in MSSQLServer, to what do you map this in .NET?

Can you convert it to Double or will you lose numbers?

like image 848
Lieven Cardoen Avatar asked Feb 13 '09 14:02

Lieven Cardoen


People also ask

What is a SQL float in C#?

The float in Microsoft SQL Server is equivalent to a Double in C#. The reason for this is that a floating-point number can only approximate a decimal number, the precision of a floating-point number determines how accurately that number approximates a decimal number.

What is float in database?

The FLOAT data type stores double-precision floating-point numbers with up to 17 significant digits. FLOAT corresponds to IEEE 4-byte floating-point, and to the double data type in C. The range of values for the FLOAT data type is the same as the range of the C double data type on your computer.

Can we convert float to int in SQL?

Convert Float to Int In this example, we will convert a float data type to integer. In the following query, we will declare a variable that data type is float and then we will use the SQL CONVERT function in order to convert float value to integer so for that we will perform data converting operation.


1 Answers

SQLServer float and C#/VB double have the same representation. This is the correct mapping. What you don't want to do is map SQL Server float to C#/VB float as that may involve a loss of precision. SQL Server real maps onto C#/VB float.

T-SQL float and real type definitions can be found at MSDN. C# double definition can be found at MSDN as well, as can the float definition.

like image 71
tvanfosson Avatar answered Sep 22 '22 00:09

tvanfosson