JAVA应用: 浮点数转化为大写中文金额
2008-01-05 08:26:07 来源:WEB开发网读入一个浮点数值,将其转化为金额的中文大写方式.
试验要求:
当金额为整数时,只表示整数部分,省略小数部分,并添加"整"字.
当金额中含有连续的0时,只需要一个"零"即可.
10的表示方式.例如110--壹佰一拾元整,10---一拾元整
--------------------------------------------------------------------------------
1import java.io.*;
2class chineseMoney...{
3 PRivate String number[]=...{"","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
4 private String unit[]=...{"","拾","佰","仟"};
5 private String small[]=...{"角","分"};
6 //private String strNumber,strUnit,strAll;
7
8 //是否在number中
9 private boolean IsInNumber(String strNumber)
10 ...{
11 boolean inNumber=false;
12 for (int i=0;i<9;i++)
13 ...{
14 if (strNumber.compareTo (number[i])==0) inNumber=true;
15 }
16 return inNumber;
17 }
18
19
20 private String SplitChineseNumber(int intUnit,String strInt)
21 ...{
22 int l=strInt.length ();
23 int j,k,zeorCountTemp=0;
24 String strUnit="",strNumber="",strAll="";
25
26 //判定在千万到万位 是否全为0,是的话,不返回“万”,返回“”;
27 boolean temp=false;
28 for (k=0;k 30 String strTemp=strInt.substring(k,k+1);
31 int intTemp=Integer.parseInt(strTemp);
32
33 if (intTemp!=0) temp=true;
34 }
35 if (temp==false)
36 ...{
37 if (intUnit==5)return "";
38 }
39
40
41 int checkK=0;
42 //正式开始转换
43 for (k=0;k 45 String strTemp=strInt.substring(k,k+1);
46 int intTemp=Integer.parseInt(strTemp);
47 strNumber= number[intTemp];
48
49 //j 从
50 j=l-1-k;
51
52 strUnit=unit[j];
53
54
55 //数值+单位
56 //假如数值=0,数值=“”
57 if (intTemp==0)
58 ...{
59 //
60 if (zeorCountTemp==0)
61 ...{
62 //单位=零
63 strUnit=strUnit.replace(''''拾'''',''''零'''');
64 strUnit=strUnit.replace(''''佰'''',''''零'''');
65 strUnit=strUnit.replace(''''仟'''',''''零'''');
66 }
67 else
68 ...{
69 //多零情况下,单位=“”
70 strUnit=strUnit.replaceAll("拾","");
71 strUnit=strUnit.replaceAll("佰","");
72 strUnit=strUnit.replaceAll("仟","");
73 }
74 zeorCountTemp++;
75 }
76 checkK=k;
77 strAll+=strNumber+strUnit;
78 }
79
80 return strAll;
81 }
82
83 private String onlyInt(int intInt)
84 ...{
85 String strInt;
86 strInt=String.valueOf(intInt);
87 int l=strInt.length();
88
89 String strAll="";
90 //按照四位 一分隔 来计算
91 if (l>8)//亿
92 ...{
93 strAll+=this.SplitChineseNumber(9,strInt.substring(0,l-8))+"亿";
94 strAll+=this.SplitChineseNumber(5,strInt.substring(l-8,l-4));
95 strAll+=this.SplitChineseNumber(1,strInt.substring(l-4,l))+"元";
96 }
97 else if (l>4)//万
98 ...{
99 strAll+=this.SplitChineseNumber(5,strInt.substring(0,l-4));
100 strAll+=this.SplitChineseNumber(1,strInt.substring(l-4,l))+"元";
101
102 }
103 else if (l>0)
104 ...{
105 strAll+=this.SplitChineseNumber(1,strInt)+"元";
106 }
107//
108//
109//
110//
111// 100101000
112 int checkL=strAll.length();
113
114 char strTemp2;
115 for (int k=1;k
赞助商链接