本文实例讲述了C#实现将商品金额小写转换成大写的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#region 【将商品金额小写转换成大写】MoneySmallToBig /// <summary> /// 将商品金额小写转换成大写 /// </summary> /// <param name="par">小写金额</param> /// <returns>处理后的大写金额</returns> public static string MoneySmallToBig( string par) { String[] Scale = { "分" , "角" , "元" , "拾" , "佰" , "仟" , "万" , "拾" , "佰" , "仟" , "亿" , "拾" , "佰" , "仟" , "兆" , "拾" , "佰" , "仟" }; String[] Base = { "零" , "壹" , "贰" , "叁" , "肆" , "伍" , "陆" , "柒" , "捌" , "玖" }; String Temp = par; 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]); 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]; result += Scale[i + 1]; } } return result; } #endregion |
希望本文所述对大家C#程序设计有所帮助。