Write it down for later use!
<summary>///amount to uppercase amount///</summary> public class Moneyconvertchinese {///<summary>
; Amount to Capital amount///</summary>///<param name= "Lowermoney" ></param>///<returns></re
Turns> public string Moneytochinese (string Lowermoney) {string functionreturnvalue = null; BOOL isnegative = false; is a negative number if (Lowermoney.trim (). Substring (0, 1) = = "-") {//is a negative number is first converted to positive Lowermoney = Lowermoney.trim ().
Remove (0, 1);
Isnegative = true;
} string strlower = null;
string strupart = null;
string strupper = null;
int itemp = 0; Retains two decimal 123.489→123.49 123.4→123.4 Lowermoney = Math.Round (double. Parse (Lowermoney), 2).
ToString ();
if (Lowermoney.indexof (".") > 0) {if (Lowermoney.indexof (".") = = Lowermoney.length-2) {
Lowermoney = Lowermoney + "0";
}} else { Lowermoney = Lowermoney + ". 00";
} strlower = Lowermoney;
ITEMP = 1;
Strupper = "";
while (itemp <= strlower.length) {switch (strlower.substring (strlower.length-itemp, 1)) {
Case ".": Strupart = "Round";
Break
Case "0": Strupart = "0";
Break
Case "1": Strupart = "one";
Break
Case "2": Strupart = "II";
Break
Case "3": Strupart = "three";
Break
Case "4": Strupart = "Restaurant";
Break
Case "5": Strupart = "WU";
Break
Case "6": Strupart = "Lu";
Break
Case "7": Strupart = "Qi";
Break
Case "8": Strupart = "ba";
Break
Case "9": Strupart = "Nine";
Break Switch (ITEMP) {Case 1:strupart = strupart + "min";
Break
Case 2:strupart = strupart + "angle";
Break
Case 3:strupart = Strupart + "";
Break
Case 4:strupart = Strupart + "";
Break
Case 5:strupart = Strupart + "Pick up";
Break
Case 6:strupart = Strupart + "Bai";
Break
Case 7:strupart = Strupart + "thousand";
Break
Case 8:strupart = Strupart + "million";
Break
Case 9:strupart = Strupart + "Pick up";
Break
Case 10:strupart = Strupart + "Bai";
Break
Case 11:strupart = Strupart + "thousand";
Break
Case 12:strupart = Strupart + "billion";
Break
Case 13:strupart = Strupart + "Pick up"; BrEak
Case 14:strupart = Strupart + "Bai";
Break
Case 15:strupart = Strupart + "thousand";
Break
Case 16:strupart = Strupart + "million";
Break
Default:strupart = Strupart + "";
Break
} strupper = Strupart + strupper;
ITEMP = itemp + 1;
} Strupper = Strupper.replace ("0 pick", "0");
Strupper = Strupper.replace ("0 bai", "0");
Strupper = Strupper.replace ("0 thousand", "0");
Strupper = Strupper.replace ("000", "0");
Strupper = Strupper.replace ("00", "0");
Strupper = Strupper.replace ("Certer", "whole");
Strupper = Strupper.replace ("0 points", "whole");
Strupper = Strupper.replace ("0 Horns", "0");
Strupper = Strupper.replace ("0 yuan", "billion Round");
Strupper = Strupper.replace ("Million Zero million Zero circle", "billion Round");
Strupper = Strupper.replace ("0", "billion");
Strupper = Strupper.replace ("0 Circle", "million Round"); Strupper = Strupper.replacE ("0", "billion");
Strupper = Strupper.replace ("0", "million");
Strupper = Strupper.replace ("0 Circle", "round");
Strupper = Strupper.replace ("00", "0"); The treatment of the amount below one circle if (strupper.substring (0, 1) = = "Round") {strupper = strupper.substring (1, Strupper.length
-1);
} if (strupper.substring (0, 1) = = "0") {strupper = strupper.substring (1, strupper.length-1);
} if (strupper.substring (0, 1) = = "Corner") {strupper = strupper.substring (1, strupper.length-1);
} if (strupper.substring (0, 1) = = "Min") {strupper = strupper.substring (1, strupper.length-1);
} if (strupper.substring (0, 1) = = "whole") {Strupper = "0 round whole";
} functionreturnvalue = Strupper;
if (isnegative = = True) {return "negative" + functionreturnvalue;
else {return functionreturnvalue;
}
}
}
Test code:
static void Main (string[] args)
{
Console.Write ("Enter the number you want to turn to uppercase:");
String str = Console.ReadLine ();
Console.WriteLine ("Uppercase:" + new Moneyconvertchinese (). Moneytochinese (str));
Console.ReadLine ();
}
Test results:
The following are additional users:
Using System; namespace ConsoleApp {///<summary>///This class implements the conversion of Arabic numerals to uppercase Chinese///This class does not discriminate against illegal numbers///please call Numtochn method///</summar Y> public class Numformat {public Numformat () {///TODO: Add constructor logic here//}//convert digital Private char
Tonum (char x) {string strchnnames= "0123456789";
String strnumnames= "0123456789";
return Strchnnames[strnumnames.indexof (x)];
}//Convert million The following integer private string Changeint (String x) {string[] strarraylevelnames=new string[4] {"", "ten", "Hundred", "thousand"};
string ret = "";
int i;
for (i=x.length-1;i>=0;i--) if (x[i] = = ' 0 ') ret = Tonum (x[i)) + ret;
else ret = Tonum (X[i]) + strarraylevelnames[x.length-1-i] + ret; while (I=ret. IndexOf ("00"))!=-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 integer private string ToInt (string x) {int len = x.length;
String ret,temp;
if (len<=4) ret = Changeint (x);
else if (len<=8) {ret = Changeint (x.substring (0,len-4)) + "Million";
temp = Changeint (x.substring (len-4,4)); if (temp.
IndexOf ("thousand") ==-1 && temp!= "") ret + + "0" + temp;
else ret = temp;
else {ret=changeint (x.substring (0,len-8)) + "billion";
Temp=changeint (x.substring (len-8,4)); if (temp.
IndexOf ("thousand") ==-1 && temp!= "") ret + + "0" + temp;
else ret = temp;
ret = "million";
temp = Changeint (x.substring (len-4,4)); if (temp.
IndexOf ("thousand") ==-1 && temp!= "") ret + + "0" + temp;
else ret = temp;
} int i; if (I=ret. IndexOf ("0"))!=-1) ret = ret.
Remove (i+1,1); while (I=ret. IndexOf ("00"))!=-1) ret = ret.
Remove (i,1); if (Ret[ret. length-1]== ' 0 ' && ret. LENGTH>1) ret = ret. Remove (ret.
length-1,1);
return ret;
private string ToDecimal (String x) {string ret= "";
for (int i=0;i<x.length;i++) ret + tonum (x[i]); return ret;
public string Numtochn (string x) {if (x.length==0) return ";
String ret= "";
if (x[0]== '-') {ret= "negative";
X=x.remove (0,1); } if (x[0).
ToString () = = ".")
x= "0" +X; if (x[x.length-1).
ToString () = = ".")
X=x.remove (x.length-1,1); if (X.indexof (".") >-1) ret + toint (x.substring (0,x.indexof ("."))) + "dot" +todecimal (x.substring (X.indexof (".")
+1));
else ret = ToInt (x);
return ret; }
}
}
Test Engineering
Using System;
Namespace ConsoleApp
{
class MainClass
{
static void Main (string[] args)
{/
*
System.Console.WriteLine ("Hello, the world!");
System.Console.WriteLine ("My love!");
Classtest ct = new classtest ();
System.Console.WriteLine (CT). Get_str ());
*
///*/
/overloaded operator
Myvector v1 = new Myvector (5);
Myvector v2 = new Myvector (4, 3);
Myvector v3 = new Myvector ();
V3 = v1 + v2;
System.Console.WriteLine ("{0} Test", V3.) Length);
*
///Convert to uppercase digital
numformat NF = new Numformat ();
string x;
while (true)
{
Console.Write ("x=");
x = Console.ReadLine ();
if (x = = "") Break;
Console.WriteLine ("{0}={1}", X, NF.) Numtochn (x));}}