パブリック クラス RMBConverter2 は IRMBConverter を実装します {
private static Final String [] RMB_NUMBER ={"zero","one","two","three","four","5","鲁","七","八","九"};
private static Final String [] RMB_ATTR = {"元","十","百","千","万","十","百","千","100 million","十", " "百"、"銭"、"ワン"、"十"、"百"、"銭"};
private static Final String[] RMB_FEN = {"分","角度"};
@オーバーライド
public String change2RMB(double counts) {
StringBuffer rsBuf = new StringBuffer();
if (カウント == 0L) {
「ゼロ」を返します。
}
if (カウント < 0)
rsBuf.append("ネガティブ");
String zheng = strConverse(String.valueOf((long)counts));
String xiao = strConverse(String.valueOf(Math.round((カウント - (ロング)カウント)*100)));
char [] zhengArray = zheng.toCharArray();
char [] xiaoArray = xiao.toCharArray();
int zLength = zhengArray.length;
int xLength = xiaoArray.length;
List<String> zhengList = new ArrayList<String>();
for(int i =0; i< zLength; i++) {
int 値 = Integer.parseInt(""+zhengArray[i]);
if (値 == 0 && (i != 4) && (i != 8) && i != 0) {
zhengList.add(RMB_NUMBER[値]);
}それ以外 {
zhengList.add(RMB_NUMBER[値]+
RMB_ATTR[i]);
}
}
for(int i = zhengList.size()-1; i>=0; i--) {
rsBuf.append(zhengList.get(i));
}
for(int i =0; i<xLength ;i++) {
int 値 = Integer.parseInt(""+xiaoArray[i]);
if (値 > 0 ) {
rsBuf.append(RMB_NUMBER[値])
.append(RMB_FEN[xLength-i-1]);
}
}
文字列 rs = rsBuf.toString();
rs = rs.replaceAll("ゼロ+", "ゼロ");
rs = rs.replaceAll("ゼロ元", "元");
rs = rs.replaceAll("00,000", "10,000");
rs = rs.replaceAll("0億", "1億");
rs = rs.replaceAll("10億", "10億");
rsを返します。
}
プライベート String strConverse(String str) {
StringBuffer rs = new StringBuffer();
char [] strArray = str.toCharArray();
for(int i = str.length()-1; i>=0; i--) {
rs.append(strArray[i]);
}
rs.toString() を返します。
}
public static void main(String args []) {
RMBConverter2 c2 = 新しい RMBConverter2();
System.out.println(c2.change2RMB(2001004.10));
System.out.println(c2.change2RMB(2000000.10));
System.out.println(c2.change2RMB(0L));
System.out.println(c2.change2RMB(1121000010000000L));
}
}