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
I think the main question has been answered here but I feel compelled to add something for the section of the question that states that this works.
_AccelLimit = (float)(double)exercise["DefaultAccelLimit"];
The reason this "works" and the reason it "doesn't feel right" is that you are downgrading the double to a float by the second cast (the one on the left) so you are losing precision and effectively telling the compiler that it is ok to truncate the value returned.
In words this line states... Get an object (that happens to hold a double in this case) Cast the object in to a double (losing all the object wrapping) Cast the double in to a float (losing all the fine precision of a double)
e.g. If the value is say 0.0124022806089461 and you do the above then the value of AccelLimit will be 0.01240228
as that is the extent of what a float in c# can get from the double value. Its a dangerous thing to do and I am pretty sure its a truncation too rather than a rounding but someone may want to confirm this as I am not sure.