la classe publique RMBConverter2 implémente IRMBConverter {
chaîne finale statique privée [] RMB_NUMBER ={"zéro","un","deux","trois","quatre","五","鲁","七","八","九"} ;
chaîne finale statique privée [] RMB_ATTR = {"元","十","百","千","万","十","百","千","100 millions","十", " "Cent", "Qian", "Wan", "Dix", "Cent", "Qian"};
chaîne finale statique privée[] RMB_FEN = {"minutes","angle"};
@Outrepasser
public String change2RMB (comptes doubles) {
StringBuffer rsBuf = new StringBuffer();
si (compte == 0L) {
renvoyer "zéro" ;
}
si (compte < 0)
rsBuf.append("négatif");
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>();
pour(int i =0; i< zLength; i++) {
valeur int = Integer.parseInt(""+zhengArray[i]);
if (value == 0 && (i != 4) && (i != 8) && i != 0) {
zhengList.add(RMB_NUMBER[valeur]);
}autre {
zhengList.add(RMB_NUMBER[valeur]+
RMB_ATTR[i]);
}
}
for(int i = zhengList.size()-1; i>=0; i--) {
rsBuf.append(zhengList.get(i));
}
pour(int je =0; i<xLength ;i++) {
valeur int = Integer.parseInt(""+xiaoArray[i]);
si (valeur > 0 ) {
rsBuf.append(RMB_NUMBER[valeur])
.append(RMB_FEN[xLength-i-1]);
}
}
Chaîne rs = rsBuf.toString();
rs = rs.replaceAll("zéro+", "zéro");
rs = rs.replaceAll("zéro yuan", "yuan");
rs = rs.replaceAll("00 000", "10 000");
rs = rs.replaceAll("000 millions", "100 millions");
rs = rs.replaceAll("milliard", "milliard");
retourner rs;
}
chaîne privée strConverse (chaîne str) {
StringBufferrs = 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 = nouveau 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));
}
}