C#實現將商品金額小寫轉換成大寫
阿新 • • 發佈:2020-08-27
/// <summary> /// 將商品金額小寫轉換成大寫 /// </summary> /// <param name="par">小寫金額</param> /// <returns>處理後的大寫金額</returns> public static string MoneySmallToBig(string par) { String[] Scale = { "分", "角", "元", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟", "兆", "拾", "佰", "仟" }; String[] Base = { "零", "壹", "貳", "叄", "肆", "伍", "陸", "柒", "捌", "玖" }; string Temp = par; object str = Temp[1]; string result = null; int index = Temp.IndexOf(".", 0, Temp.Length);//判斷是否有小數點 if(index != -1) { Temp = Temp.Remove(Temp.IndexOf("."), 1); for (int i = Temp.Length; i > 0; i--) { int Data = Convert.ToInt16(Temp[Temp.Length - i]);//得到對應的ASCII碼值 result += Base[Data - 48]; result+= Scale[i - 1]; } } else { for (int i = Temp.Length; i > 0; i--) { int Data = Convert.ToInt16(Temp[Temp.Length - i]); result += Base[Data - 48]; Console.WriteLine(result); result += Scale[i + 1]; Console.WriteLine(result); } } //Console.WriteLine(Base[43]); return result; }