Posts
247
Comments
67
Trackbacks
4
Kleine Funktion: ToValidDecimal

Hier eine kleine Funktion die einen übergebenen Wert in einen Decimal-Wert umwandelt:

static public decimal ToValidDecimal(object n, NumberFormatInfo nfi ) {

      if(n==null) return 0;

      if(n.GetType() == typeof(decimal)) return (decimal)n;
      if(n.GetType() == typeof(int)) return (decimal)n;
      if(n.GetType() == typeof(long)) return (decimal)n;
      if(n.GetType() == typeof(string)) {

            try {
                  return decimal.Parse( (string)n, nfi );
            }
            catch( Exception ) {
                  return (decimal)0;
            }

      }

      return (decimal)0;
}

posted on Thursday, February 28, 2008 9:30 AM Print
Comments
No comments posted yet.

Post Comment

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