1. Processing of input numbers
Use regular expressions to determine whether the input numbers meet the currency format, and whether the length of the string before the decimal point is not greater than 13.
2. Source code
1、Main()
// Lowercase number to uppercase Chinese characters// The length of the number before the decimal point is <=13, that is, no more than one billionusing ; namespace NumtoUpperChinese { partial class Program { /// <summary> /// Determine whether the input is in currency format, whether it is before the decimal point <=13, /// </summary> /// <param name="args"></param> private static void Main(string[] args) { (args); ("Please enter the string to be judged (currency format)"); string input = ()!.ToString(); if (input!="") { bool isValidFormat = IsValidCurrencyFormat(input); if (isValidFormat) { ((input)); } else { ("The entered currency format is invalid"); } } else { ("The input number cannot be empty, please re-enter!", "hint"); } } static bool IsValidCurrencyFormat(string input) { Regex regex = MyRegex(); // Define regular expression patterns return (input); // Return matching results } [GeneratedRegex(@"^\d{0,13}(\.\d+)?$")] private static partial Regex MyRegex(); } } //Run result:/* Please enter the string to judge (currency format) 999999999999999.99 Jiuwanjiuqianjiuqianjiuqianjiuqianjiuqianjiuqianjiuqianjiuqianjiuqianjiuqiuqianjiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqiuqi */
2. Class library
// Class librarynamespace NumtoUpperChinese { internal static class NumtoUpper { /// <summary> /// Convert the amount into Chinese capital /// </summary> /// <param name="LowerMoney">eg:10.74</param> /// <returns></returns> public static string MoneyToUpper(string LowerMoney) { string? ReturnValue; bool IsNegative = false; // Is it a negative number if (()[..1] == "-") { // If it is a negative number, it will first be converted to a positive number LowerMoney = ().Remove(0, 1); IsNegative = true; } string? strLower; string? strUpart = null; string? strUpper; int iTemp; // Keep two decimal places 123.489→123.49123.4→123.4 LowerMoney = ((LowerMoney), 2).ToString(); if (('.') > 0) { if (('.') == - 2) { LowerMoney += ('0'); } } else { LowerMoney += ".00"; } strLower = LowerMoney; iTemp = 1; strUpper = ""; while (iTemp <= ) { switch (( - iTemp, 1)) { case ".": strUpart = "round"; break; case "0": strUpart = "zero"; break; case "1": strUpart = "one"; break; case "2": strUpart = "two"; break; case "3": strUpart = "Three"; break; case "4": strUpart = "Si"; break; case "5": strUpart = "Wu"; break; case "6": strUpart = "land"; break; case "7": strUpart = "Qi"; break; case "8": strUpart = "eight"; break; case "9": strUpart = "Nine"; break; } strUpart = iTemp switch { 1 => strUpart + "point", 2 => strUpart + "horn", 3 => strUpart + "", 4 => strUpart + "", 5 => strUpart + "pickup", 6 => strUpart + "Bai", 7 => strUpart + "thousand", 8 => strUpart + "Ten thousand", 9 => strUpart + "pickup", 10 => strUpart + "Bai", 11 => strUpart + "thousand", 12 => strUpart + "100 million", 13 => strUpart + "pickup", 14 => strUpart + "Bai", 15 => strUpart + "thousand", 16 => strUpart + "Ten thousand", _ => strUpart + "", }; strUpper = strUpart + strUpper; iTemp++; } strUpper = ("Zero Pickup", "zero"); strUpper = ("Zerobai", "zero"); strUpper = ("Zero Thousand", "zero"); strUpper = ("Zero Zero", "zero"); strUpper = ("Zero Zero", "zero"); strUpper = ("Zero Angle Zero Points", "all"); strUpper = ("Zero points", "all"); strUpper = ("Zero Angle", "zero"); strUpper = ("Zero billions and millions", "Biyiyuan"); strUpper = ("Number of ten thousand", "Biyiyuan"); strUpper = ("Zero billions", "100 million"); strUpper = ("Zero Ten Thousand Rounds", "Ten Thousand Rounds"); strUpper = ("Zero Billion", "100 million"); strUpper = ("Zero Ten Thousand", "Ten thousand"); strUpper = ("Zero circle", "round"); strUpper = ("Zero Zero", "zero"); // Processing of amounts below one yuan if (strUpper[..1] == "round") { strUpper = strUpper[1..]; } if (strUpper[..1] == "zero") { strUpper = strUpper[1..]; } if (strUpper[..1] == "horn") { strUpper = strUpper[1..]; } if (strUpper[..1] == "point") { strUpper = strUpper[1..]; } if (strUpper[..1] == "all") { strUpper = "Zero round"; } ReturnValue = strUpper; if (IsNegative == true) { return "burden" + ReturnValue; } else { return ReturnValue; } } } }
The above is the detailed content of C#'s currency amount to convert Chinese characters to capitalization. For more information about converting C# into capitalization, please pay attention to my other related articles!