【C#】Decimal的类型判断!

类别:.NET开发 点击:0 评论:0 推荐:

      本人在写这些类方法或函数的时候,难免有些错误或bug存在,请各位网友多多指教![email protected]

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WinMarket
{
 /// <summary>
 /// Classfun 的摘要说明。
 /// </summary>
 public class Classfun
 {
    private bool   IsBool;
  
  public Classfun()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
 //--------------判断是否是Decimal类型------------

  public bool IsDecimal(string TBstr0)
  {
   string Intstr0="1234567890";
   string IntSign0,StrInt,StrDecimal;
   int IntIndex0,IntSubstr,IndexInt;
   int decimalbool=0;
   int db=0;
   bool Bf,Bl;
   if(TBstr0.Length>2)
   {
                IntIndex0=TBstr0.IndexOf("."); 
    if(IntIndex0!=-1)
    {
                  string StrArr=".";
      char[] CharArr=StrArr.ToCharArray();
                  string[] NumArr=TBstr0.Split(CharArr);
     IndexInt=NumArr.GetUpperBound(0);
     if(IndexInt>1)
     {
      decimalbool=1;
     }
     else
     {
                        StrInt=NumArr[0].ToString();
      StrDecimal=NumArr[1].ToString();
        //--- 整数部分-----
         if(StrInt.Length>0)
         {
          if(StrInt.Length==1)
          {
           IntSubstr=Intstr0.IndexOf(StrInt);
           if(IntSubstr!=-1)
           {
            Bf=true;
           }
           else
           {
            Bf=false;
           }
          }
          else
          {
           for(int i=0;i<=StrInt.Length-1;i++)
           {
            IntSign0=StrInt.Substring(i,1).ToString();
            IntSubstr=Intstr0.IndexOf(IntSign0);
            if(IntSubstr!=-1)
            {
               db=db+0;
            }
            else
            {
             db=i+1;
             break;
            }
           }

           if(db==0)
           {
            Bf=true;
           }
           else
           {
            Bf=false;
           }
          }
         }
         else
         {
            Bf=true;
         }
               //----小数部分----
        if(StrDecimal.Length>0)
        {
         for(int j=0;j<=StrDecimal.Length-1;j++)
         {
          IntSign0=StrDecimal.Substring(j,1).ToString();
          IntSubstr=Intstr0.IndexOf(IntSign0);
          if(IntSubstr!=-1)
          {
           db=db+0;
          }
          else
          {
           db=j+1;
           break;
          }
         }
         if(db==0)
         {
          Bl=true;
         }
         else
         {
          Bl=false;
         }
        }
        else
        {
         Bl=false;
        }
      if((Bf&&Bl)==true)
      {
                           decimalbool=0;
      }
      else
      {
                           decimalbool=1;
      }
      
     }

    }
    else
    {
     decimalbool=1;
    }

   }
   else
   {
             decimalbool=1;
   }

    if(decimalbool==0)
    {
     IsBool=true;
    }
    else
    {
     IsBool=false;
    }

    return IsBool;
  }

 }
}


本文地址:http://com.8s8s.com/it/it42701.htm