Hier eine kleine Funktion um ein beliebiges Objekt in einen Float-Wert umzuwandeln:
static public float ToValidFloat(object n) {
if(n==null) return 0;
if(n.GetType() == typeof(string)) {
try {
return float.Parse((string)n);
}
catch( Exception ) {
return 0f;
}
}
try {
return (float)n;
}
catch( InvalidCastException ) {
return 0f;
}
}