Die öffentliche Klasse RMBConverter2 implementiert IRMBConverter {
private static final String [] RMB_NUMBER ={"null", "eins", "zwei", "drei", "vier", "五", "鲁", "七", "八", "九"};
private static final String [] RMB_ATTR = {"元", "十", "百", "千", "万", "十", "百", "千", "100 million", "十", „ „Hundert“, „Qian“, „Wan“, „Zehn“, „Hundert“, „Qian“};
private static final String[] RMB_FEN = {"Minuten", "Winkel"};
@Override
public String change2RMB(double counts) {
StringBuffer rsBuf = new StringBuffer();
if (counts == 0L) {
„Null“ zurückgeben;
}
if (counts < 0)
rsBuf.append("negativ");
String zheng = strConverse(String.valueOf((long)counts));
String xiao = strConverse(String.valueOf(Math.round((counts - (long)counts)*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 value = Integer.parseInt(""+zhengArray[i]);
if (value == 0 && (i != 4) && (i != 8) && i != 0) {
zhengList.add(RMB_NUMBER[Wert]);
}anders {
zhengList.add(RMB_NUMBER[Wert]+
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 value = Integer.parseInt(""+xiaoArray[i]);
if (Wert > 0) {
rsBuf.append(RMB_NUMBER[Wert])
.append(RMB_FEN[xLength-i-1]);
}
}
String rs = rsBuf.toString();
rs = rs.replaceAll("null+", "null");
rs = rs.replaceAll("null Yuan", "Yuan");
rs = rs.replaceAll("00.000", "10.000");
rs = rs.replaceAll("000 Millionen", "100 Millionen");
rs = rs.replaceAll("billion", "billion");
rs zurückgeben;
}
privater 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]);
}
return rs.toString();
}
public static void main(String args []) {
RMBConverter2 c2 = new 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));
}
}