目前試用了個還沒有發現什麼問題,感覺還行吧,所以發來供大家參考
1. 引用命名空間:using System.Text.RegularExpressions;(操作正則表達式)
2. 小寫轉大寫






































3. 獲得數位位數






















































4. 轉換
1
public static string ConventGig(string money)
2
{
3
string strTemp = money;
4
string Decimal = ""; //小數
5
string strValue = "";
6
string strDecimal = "";
7
if( money.IndexOf(".")>0)
8
{
9
strDecimal = "點";
10
strTemp=money.Substring(0,money.IndexOf("."));
11
Decimal = money.Substring(money.IndexOf(".")+1);
12
}
13
try
14
{
15
strTemp = Convert.ToInt64(strTemp).ToString();
16
}
17
catch
18
{
19
return "輸入不正確的數據!";
20
}
21
int iLen = strTemp.Length;
22
if(strTemp.Length>16) return "數據過大無法轉換";
23
for(int i=0; i<strTemp.Length; i++)
24
{
25
strValue += sToh(strTemp.Substring(i,1)) + getBit(iLen);
26
iLen--;
27
}
28
//小數
29
for(int i=0; i<Decimal.Length; i++)
30
{
31
strDecimal += sToh(Decimal.Substring(i,1));
32
}
33
Regex regex = new Regex("零+[拾,佰,仟,萬,億,兆]");
34
strValue = regex.Replace(strValue,"零");
35
regex = new Regex("零{2,16}");
36
strValue = regex.Replace(strValue,"零");
37
regex = new Regex("(萬|億|兆){1}零");
38
strValue = regex.Replace(strValue,"$1");
39
regex = new Regex("點$");
40
strDecimal = regex.Replace(strDecimal,"");
41
regex = new Regex("零+$");
42
strDecimal = regex.Replace(strDecimal,"");
43
return strValue + strDecimal;
44
}

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

36

37

38

39

40

41

42

43

44

5. 試用
0.1000500 輸出的結果為 >> 零點壹零零零伍
1008000500452008.12345 輸出的結果為 >> 壹仟零捌兆伍億肆拾伍萬貳仟零捌點壹貳參肆伍