首页  编辑  

中文数字表达式

Tags: /C#/字符串处理/   Date Created:

string NumberCn( double ANumber)

{

    const string cPointCn = " ;

    const string cNumberCn = " ;

    string S = ANumber . ToString();

    if (S == "0" ) return "" + cPointCn[ 0 ];

    if ( ! S . Contains( "." )) S += "." ;

    int P = S . IndexOf( "." );

    string Result = "" ;

   

    for ( int i = 0 ; i < S . Length; i ++ )

   {

        if (P == i)

       {

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

           Result = Result . Replace( " , " );

       }

        else

       {

           if (P > i)

               Result += "" + cNumberCn[S[i] - '0' ] + cPointCn[P - i - 1 ];

            else Result += "" + cNumberCn[S[i] - '0' ];

       }

   }

    if (Result . Substring(Result . Length - 1 , 1 ) == "" + cPointCn[ 0 ])

       Result = Result . Remove(Result . Length - 1 ); //

   

    if (Result[ 0 ] == cPointCn[ 0 ])

       Result = cNumberCn[ 0 ] + Result; //

    if ((Result . Length > 1 ) && (Result[ 1 ] == cPointCn[ 1 ]) &&

      (Result[ 0 ] == cNumberCn[ 1 ]))

      Result = Result . Remove( 0 , 1 ); //

    return Result;

}

string MoneyCn( double ANumber)

{

    if (ANumber == 0 ) return " ;

    string Result = NumberCn( Math . Truncate(ANumber * 100 ) / 100 );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

   Result = Result . Replace( " , " );

    if (Result . Contains( " ))

   {

        int P = Result . IndexOf( " );

       Result = Result . Insert(P + 3 , " );

       Result = Result . Insert(P + 2 , " );

       Result = Result . Replace( " , " );

       Result = Result . Replace( " , " );

       Result = Result . Replace( " , "" );

       Result = Result . Replace( " , "" );

       Result = Result . Replace( " , "" );

        if (Result . Substring( 0 , 2 ) == " )

           Result = Result . Replace( " , "" );

   } else Result += " ;

   Result = " + Result;

    return Result;

}