Arabic numerals to lowercase Chinese numerals

Source: Internet
Author: User

C # version

View Code

Using System; using System. collections. generic; using System. text; namespace NumberConventer {class Class1 {private string [] CnNum = {"0", "1", "2", "3", "4", "5 ", "6", "7", "8", "9"}; private string [] ShiNum = {"thousands", "", "10", "hundreds "}; private string [] WanNum = {"", "", ""}; private string NumTh, OutCn; private bool isNumber (string aaa) {try {int bbb = Convert. toInt16 (aaa); return true;} catch {Return false ;}/// determines whether it is a digital private string ChangeChineseNum (string Number, int Numlan) {bool Zero = false, Wan = false, Hand = true; // If zero is used, whether to output the Chinese character "zero" is required. If Wan is the first to output the Chinese character "Ten Thousand" or "hundred million", Hand determines whether it is the first non-zero number. Int NumTemp; bool Booltemp = Int32.TryParse (Number, out NumTemp); if (! Booltemp) {NumTemp = 0 ;}for (int I = 1; I <= Numlan; I ++) {NumTh = Number. substring (I-1, 1); int NowNum, NowTh = Numlan + 1-I; if (isNumber (NumTh) {NowNum = Convert. toInt16 (NumTh); // OutCn = OutCn + CnNum [I];} else {break;} if (NowNum = 0) {if (Hand = true) {continue;} else {Zero = true ;}} else {Wan = true; if (Hand = true) {if (NumTemp> 9 & NumTemp <20) {OutCn = OutCn + ShiNum [NowTh % 4];} else {OutCn = OutCn + CnNum [NowNum] + ShiNum [NowTh % 4];} Hand = false ;} else {if (Zero = false) {OutCn = OutCn + CnNum [NowNum] + ShiNum [NowTh % 4];} else {OutCn = OutCn + CnNum [0] + CnNum [NowNum] + ShiNum [NowTh % 4]; Zero = false ;}}} if (Wan = true & (NowTh-1) % 4 = 0) {OutCn = OutCn + WanNum [(NowTh-1)/4) % 2]; for (int j = (NowTh-1)/8; j> 0; j = j -1) {OutCn = OutCn + WanNum [2];} Wan = false;} if (isNumber (NumTh) {return OutCn ;} else {return "contains non-Arabic characters! Please correct it! ";}}}}

Javascript version

View Code

Function ChangeChineseNum (Number) {var isNumber = function (aaa) {try {parseInt (aaa); return true ;}catch (err) {return false ;}}; var CnNum = ["zero", "one", "two", "three", "four", "five", "Six", "Seven", "eight ", "9"]; var ShiNum = ["Thousand", "", "Ten", "Hundred"]; var WanNum = ["", "Ten ", ""]; var NumTh, OutCn = ""; var Zero = false, Wan = false, Hand = true; // zero indicates whether the Chinese character "Zero" needs to be output ", wan determines whether to output the Chinese character "" or "million", and Hand determines whether it is the first non-zero number. Var Numlan; var NumTemp; var Booltemp; if (isNumber (Number) {NumTemp = parseInt (Number); Numlan = NumTemp. toString (). length;} else {NumTemp = 0; Numlan = 0;} for (var I = 1; I <= Numlan; I ++) {NumTh = Number. toString (). substring (I-1, I); var NowNum, NowTh = Numlan + 1-I; if (isNumber (NumTh) {NowNum = parseInt (NumTh ); // OutCn = OutCn + CnNum [I];} else {break;} if (NowNum = 0) {if (Hand = true) {continue;} else {Zero = true;} else {Wan = true; if (Hand = true) {if (NumTemp> 9 & NumTemp <20) {OutCn = OutCn + ShiNum [NowTh % 4];} else {OutCn = OutCn + CnNum [NowNum] + ShiNum [NowTh % 4];} Hand = false;} else {if (Zero = false) {OutCn = OutCn + CnNum [NowNum] + ShiNum [NowTh % 4];} else {OutCn = OutCn + CnNum [0] + CnNum [NowNum] + ShiNum [NowTh % 4]; Zero = fals E ;}}if (Wan = true & (NowTh-1) % 4 = 0) {OutCn = OutCn + WanNum [(NowTh-1)/4) % 2]; for (var j = parseInt (NowTh-1)/8); j> 0; j = j-1) {OutCn = OutCn + WanNum [2] ;}wan = false ;}}if (isNumber (NumTh) {return OutCn ;}else {return "contains non-Arabic characters! Please correct it! ";}}

 

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.