C\#대소 문자 변환(금액)인 스 턴 스 코드

Class:EcanRMB.cs

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

 namespace Jxc.WinClient.BLL
 {
     public class EcanRMB
     {
         /// <summary>
         ///
         /// </summary>
         /// <param name="num"> </param>
         /// <returns> </returns>
         public string CmycurD(decimal num)
         {
             string str1 = " ";            //0-9
             string str2 = " "; //
             string str3 = "";    // num
             string str4 = "";    //
             string str5 = "";  //
             int i;    //
             int j;    //num 100
             string ch1 = "";    //
             string ch2 = "";    //
             int nzero = 0;  //
             int temp;            // num

             num = Math.Round(Math.Abs(num), 2);    // num 2
             str4 = ((long)(num * 100)).ToString();        // num 100
             j = str4.Length;      //
             if (j > 15) { return " "; }
             str2 = str2.Substring(15 - j);   // str2 。 :200.55,j 5 str2=

             //
             for (i = 0; i < j; i++)
             {
                 str3 = str4.Substring(i, 1);          //
                 temp = Convert.ToInt32(str3);      //
                 if (i != (j - 3) && i != (j - 7) && i != (j - 11) && i != (j - 15))
                 {
                     // 、 、 、
                     if (str3 == "0")
                     {
                         ch1 = "";
                         ch2 = "";
                         nzero = nzero + 1;
                     }
                     else
                     {
                         if (str3 != "0" && nzero != 0)
                         {
                             ch1 = " " + str1.Substring(temp * 1, 1);
                             ch2 = str2.Substring(i, 1);
                             nzero = 0;
                         }
                         else
                         {
                             ch1 = str1.Substring(temp * 1, 1);
                             ch2 = str2.Substring(i, 1);
                             nzero = 0;
                         }
                     }
                 }
                 else
                 {
                     // , , ,
                     if (str3 != "0" && nzero != 0)
                     {
                         ch1 = " " + str1.Substring(temp * 1, 1);
                         ch2 = str2.Substring(i, 1);
                         nzero = 0;
                     }
                     else
                     {
                         if (str3 != "0" && nzero == 0)
                         {
                             ch1 = str1.Substring(temp * 1, 1);
                             ch2 = str2.Substring(i, 1);
                             nzero = 0;
                         }
                         else
                         {
                             if (str3 == "0" && nzero >= 3)
                             {
                                 ch1 = "";
                                 ch2 = "";
                                 nzero = nzero + 1;
                             }
                             else
                             {
                                 if (j >= 11)
                                 {
                                     ch1 = "";
                                     nzero = nzero + 1;
                                 }
                                 else
                                 {
                                     ch1 = "";
                                     ch2 = str2.Substring(i, 1);
                                     nzero = nzero + 1;
                                 }
                             }
                         }
                     }
                 }
                 if (i == (j - 11) || i == (j - 3))
                 {
                     // ,
                     ch2 = str2.Substring(i, 1);
                 }
                 str5 = str5 + ch1 + ch2;

                 if (i == j - 1 && str3 == "0")
                 {
                     // ( ) 0 , “ ”
                     str5 = str5 + ' ';
                 }
             }
             if (num == 0)
             {
                 str5 = " ";
             }
             return str5;
         }

         /**/
         /// <summary>
         /// , CmycurD(decimal num)
         /// </summary>
         /// <param name="num"> , decimal</param>
         /// <returns></returns>
         public string CmycurD(string numstr)
         {
             try
             {
                 decimal num = Convert.ToDecimal(numstr);
                 return CmycurD(num);
             }
             catch
             {
                 return " !";
             }
         }
     }
 }
호출:

  EcanRMB rmb = new EcanRMB();
  string Rmb = txtAmount.Text.Replace(",", "").Replace("-","");
  label9.Text = rmb.CmycurD(Rmb);
  label11.Text = Convert.ToDecimal(txtAmount.Text).ToString("###,###,###.00");

좋은 웹페이지 즐겨찾기