Howdy, I have a DataRow pulled out of a DataTable from a DataSet. I am accessing a column that is defined in SQL as a float datatype. I am trying to assign that value to a local variable (c# float datatype) but am getting an InvalidCastExecption
DataRow exercise = _exerciseDataSet.Exercise.FindByExerciseID(65); _AccelLimit = (float)exercise["DefaultAccelLimit"];
Now, playing around with this I did make it work but it did not make any sense and it didn't feel right.
_AccelLimit = (float)(double)exercise["DefaultAccelLimit"];
Can anyone explain what I am missing here?
Float is an approximate number data type used to store a floating-point number. float (n) - n is the number of bits that are used to store the mantissa in scientific notation. Range of values: - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308. Storage size: 4 Bytes if n = 1-9 and 8 Bytes if n = 25-53 – default = ...
Float & Real Data Types in SQL Server uses the floating-point number format. Real is a Single Precision Floating Point number, while Float is a Double Precision Floating Point number. The Floating point numbers can store very large or very small numbers than decimal numbers.
float [ (n) ] Where n is the number of bits that are used to store the mantissa of the float number in scientific notation and, therefore, dictates the precision and storage size. If n is specified, it must be a value between 1 and 53. The default value of n is 53.
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.
A SQL float is a double according to the documentation for SQLDbType.
A float in SQL is a Double in the CLR (C#/VB). There's a table of SQL data types with the CLR equivalents on MSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With