kelas publik RMBConverter2 mengimplementasikan IRMBConverter {
String final statis pribadi [] RMB_NUMBER ={"nol","satu","dua","tiga","empat","五","鲁","七","八","九"};
String final statis pribadi [] RMB_ATTR = {"元", "十", "百", "千", "万", "十", "百", "千", "100 juta", "十", " "Seratus", "Qian", "Wan", "Sepuluh", "Seratus", "Qian"};
String akhir statis pribadi[] RMB_FEN = {"menit","sudut"};
@Mengesampingkan
public String change2RMB(penghitungan ganda) {
StringBuffer rsBuf = StringBuffer baru();
if (dihitung == 0L) {
kembalikan "nol";
}
jika (dihitung < 0)
rsBuf.append("negatif");
String zheng = strConverse(String.valueOf((long)counts));
String xiao = strConverse(String.valueOf(Math.round((hitungan - (panjang)hitungan)*100)));
char [] zhengArray = zheng.toCharArray();
char [] xiaoArray = xiao.toCharArray();
int zPanjang = zhengArray.panjang;
int xPanjang = xiaoArray.panjang;
Daftar<String> zhengList = ArrayList baru<String>();
untuk(int i =0; i< zPanjang; i++) {
int nilai = Integer.parseInt(""+zhengArray[i]);
if (nilai == 0 && (i != 4) && (i != 8) && i != 0) {
zhengList.add(RMB_NUMBER[nilai]);
}kalau tidak {
zhengList.add(RMB_NUMBER[nilai]+
RMB_ATTR[i]);
}
}
for(int i = zhengList.size()-1; i>=0; i--) {
rsBuf.append(zhengList.get(i));
}
untuk(int i =0; i<xPanjang ;i++) {
int nilai = Integer.parseInt(""+xiaoArray[i]);
jika (nilai > 0 ) {
rsBuf.append(RMB_NUMBER[nilai])
.append(RMB_FEN[xPanjang-i-1]);
}
}
String rs = rsBuf.toString();
rs = rs.replaceAll("nol+", "nol");
rs = rs.replaceAll("nol yuan", "yuan");
rs = rs.replaceAll("00.000", "10.000");
rs = rs.replaceAll("000 juta", "100 juta");
rs = rs.replaceAll("miliar", "miliar");
kembalikan rs;
}
pribadi String strConverse(String str) {
StringBuffer rs = StringBuffer baru();
char[] strArray = str.toCharArray();
untuk(int i = str.panjang()-1; i>=0; i--) {
rs.append(strArray[i]);
}
kembalikan rs.toString();
}
public static void main(String args []) {
RMBConverter2 c2 = RMBConverter2 baru();
Sistem.keluar.println(c2.change2RMB(2001004.10));
Sistem.keluar.println(c2.change2RMB(2000000.10));
Sistem.keluar.println(c2.change2RMB(0L));
System.out.println(c2.change2RMB(1121000010000000L));
}
}