C # convert Arabic numerals (in lower case) to uppercase Chinese (in upper case)

Source: Internet
Author: User

/// <Summary>
/// This class converts Arabic numerals to uppercase Chinese
/// This class does not identify illegal numbers. Please determine in advance whether the numbers are valid
/// </Summary>
Public class ChineseNum
{

// Convert lowercase to uppercase
Public static string GetChineseNum (string p_num)
{
ChineseNum cn = new ChineseNum ();

Return cn. NumToChn (p_num );
}

// Convert the lower-case amount to the upper-case amount

Public static string GetUpperMoney (double p_Money)
{
ChineseNum cn = new ChineseNum ();

Return cn. GetMoneyChinese (p_Money );
}

// Convert numbers
Private char CharToNum (char x)
{
String stringChnNames = "0 August 5, 1234 ";
String stringNumNames = "0123456789 ";
Return stringChnNames [stringNumNames. IndexOf (x)];
}

// Convert an integer smaller
Private string WanStrToInt (string x)
{
String [] stringArrayLevelNames = new string [4] {"", "Ten", "Hundred", "Thousand "};
String ret = "";
Int I;
For (I = x. Length-1; I> = 0; I --)
If (x [I] = 0)
{
Ret = CharToNum (x [I]) + ret;
}
Else
{
Ret = CharToNum (x [I]) + stringArrayLevelNames [x. Length-1-I] + ret;
}
While (I = ret. IndexOf ("0 "))! =-1)
{
Ret = ret. Remove (I, 1 );
}
If (ret [ret. Length-1] = 0 & ret. Length> 1)
{
Ret = ret. Remove (ret. Length-1, 1 );
}
If (ret. Length> = 2 & ret. Substring (0, 2) = "10 ")
{
Ret = ret. Remove (0, 1 );
}
Return ret;
}

// Convert the integer
Private string StrToInt (string x)
{
Int len = x. Length;
String ret, temp;
If (len <= 4)
{
Ret = WanStrToInt (x );
}
Else if (len <= 8)
{
Ret = WanStrToInt (x. Substring (0, len-4) + "Ten Thousand ";
Temp = WanStrToInt (x. Substring (len-4, 4 ));
If (temp. IndexOf ("thousands") =-1 & temp! = "")
Ret + = "zero" + temp;
Else
Ret + = temp;
}
Else
{
Ret = WanStrToInt (x. Substring (0, len-8) + "";
Temp = WanStrToInt (x. Substring (len-8, 4 ));
If (temp. IndexOf ("thousands") =-1 & temp! = "")
{
Ret + = "zero" + temp;
}
Else
{
& Nbs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.