SoFunction
Updated on 2025-03-06

C# case conversion (amount) instance code


 using System;
 using ;
 using ;
 using ;

 namespace
 {
     public class EcanRMB
     {
         /// <summary>
/// Convert RMB size
         /// </summary>
/// <param name="num">Amount</param>
/// <returns>Return to capitalization</returns>
         public string CmycurD(decimal num)
         {
string str1 = "Zero One, Two Three, Siwu Lu, Qi, Eight Nine";                                                                                                                   �
string str2 = "10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
string str3 = "";    //The value taken from the original num value
string str4 = "";    //The string form of a number
string str5 = "";  //Capacity amount form
int i;     //Loop variable
int j;       //The value of num is multiplied by the length of the string of 100
string ch1 = "";    // Chinese reading of numbers
string ch2 = "";    //How to read Chinese characters for numeric bits
int nzero = 0;  //How many consecutive zero values ​​are used to calculate
int temp;

num = ((num), 2);     //Get the absolute value of num and round it to 2 decimal places
str4 = ((long)(num * 100)).ToString();           //Multiply num 100 and convert it into a string
j = ;       //Find out the highest position
if (j > 15) { return "overflow"; }
str2 = (15 - j);   //Take out the value of str2 of the corresponding digit. For example: 200.55, j is 5, so str2=Bai Shiyuanjiaodi

//Loop out the value that needs to be converted from each bit
             for (i = 0; i < j; i++)
             {
str3 = (i, 1);                     str3 = (i, 1);                                  �
temp = Convert.ToInt32(str3);                    temp = Convert.ToInt32(str3);       //Convert to number
                 if (i != (j - 3) && i != (j - 7) && i != (j - 11) && i != (j - 15))
                 {
//When the number of digits taken is not a number above RMB, 10,000, 1000, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
                     if (str3 == "0")
                     {
                         ch1 = "";
                         ch2 = "";
                         nzero = nzero + 1;
                     }
                     else
                     {
                         if (str3 != "0" && nzero != 0)
                         {
ch1 = "zero" + (temp * 1, 1);
                             ch2 = (i, 1);
                             nzero = 0;
                         }
                         else
                         {
                             ch1 = (temp * 1, 1);
                             ch2 = (i, 1);
                             nzero = 0;
                         }
                     }
                 }
                 else
                 {
//This position is a key position such as trillions, billions, millions, and yuan
                     if (str3 != "0" && nzero != 0)
                     {
ch1 = "zero" + (temp * 1, 1);
                         ch2 = (i, 1);
                         nzero = 0;
                     }
                     else
                     {
                         if (str3 != "0" && nzero == 0)
                         {
                             ch1 = (temp * 1, 1);
                             ch2 = (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 = (i, 1);
                                     nzero = nzero + 1;
                                 }
                             }
                         }
                     }
                 }
                 if (i == (j - 11) || i == (j - 3))
                 {
//If this bit is a billion or RMB bit, it must be written
                     ch2 = (i, 1);
                 }
                 str5 = str5 + ch1 + ch2;

                 if (i == j - 1 && str3 == "0")
                 {
// When the last digit (point) is 0, add "whole"
str5 = str5 + 'whole';
                 }
             }
             if (num == 0)
             {
str5 = "zero-yuan whole";
             }
             return str5;
         }

         /**/
         /// <summary>
/// A overload, converting the string into a number first and calling CmycurD(decimal num)
         /// </summary>
/// <param name="num">The amount entered by the user, the string form has not been converted to decimal</param>
         /// <returns></returns>
         public string CmycurD(string numstr)
         {
             try
             {
                 decimal num = (numstr);
                 return CmycurD(num);
             }
             catch
             {
return "non-digital form!";
             }
         }
     }
 }