To write a small method of converting the date, although very short, but need to consider the things are quite a bit, record.
/// <summary> ///Convert a date to Chinese capital///Example: 19,957/// </summary> Public classChinesenumberhelper {Staticdictionary<int,string> _thenumofchinesecapital =Newdictionary<int,string>() { {0,"0"}, {1,"a"}, {2,"two"}, {3,"three"}, {4,"Four"}, {5,"Five"}, {6,"Six"}, {7,"Seven"}, {8,"Eight"}, {9,"Nine"}, {Ten,"10"} }; Public Static stringConvertostring (ObjectNumber , Numbertype numtype) { varinput =convert.tostring (number); intValidateint; if(string. Isnullorwhitespace (input) | | !int. TryParse (Input, outvalidateint)) Throw NewArgumentException (" Number"); if(Validateint = =0) Throw NewArgumentException (" Number"); //more verification If it is the date of the month and day of input if(Numtype = = Numbertype.day | | numtype = = numbertype.day) && input. Length = =2) Input= input. TrimStart ('0'); StringBuilder OutPut=NewStringBuilder (); Switch(numtype) { Casenumbertype.year: for(inti =0; I < input. Length; i++) { varIntval =Convert.ToInt32 (Input[i]. ToString ()); Output.append (_thenumofchinesecapital[intval]); } Break; CaseNumbertype.moth: CaseNumbertype.day:if(Validateint <Ten) {output.append (_thenumofchinesecapital[convert.toint32 (input[0]. ToString ())]); } Else if(Validateint = =Ten) {output.append (_thenumofchinesecapital[validateint]); } Else { if(Validateint > +) Output.append (_thenumofchinesecapital[convert.toint32 (input[0]. ToString ())]); Output.append (_thenumofchinesecapital[Ten]); if(input[1] !='0') Output.append (_thenumofchinesecapital[convert.toint32 (input[1]. ToString ())]); } Break; } returnoutput.tostring (); } } Public enumnumbertype {year, moth, day}
Convert date to Chinese capital number