Posts
231
Comments
64
Trackbacks
4
Kleine Funktion: ToValidDouble

Hier eine kleine Funktion um ein beliebiges Objekt in einen Double-Wert umzuwandeln:

static public double ToValidDouble( object n ) {
      if( n==null ) return 0;
      if( n.GetType() == typeof(string) ) {
            try {
                  return Double.Parse( (string)n );
            }
            catch( Exception ) {
                  return 0.0;
            }
      }
      try {
            return (double)n;
      }
      catch( InvalidCastException ) {
            return 0.0;
      }
}

posted on Thursday, March 20, 2008 12:15 PM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 5 and 6 and type the answer here: