How do you convert an object (such as a Hashtable element) to a float?
Is there a method better than parseFloat(obj.ToString())
, where obj
is the object you want converted to float?
How do you convert an object (such as a Hashtable element) to a float?
Is there a method better than parseFloat(obj.ToString())
, where obj
is the object you want converted to float?
In C# you can cast with the value-cast operator:
float myFloat = (float) obj;
But this only works if you initially put a float into the Hashtable (or any weak-typed collection). If it was a string, then no there is no other way (actually you could write implicit operator extensions but I discourage to do it).