/** * @note 根據傳入的數字,獲取同義漢字 * @author ydz */ public String convert(Double number) { //數字對應的漢字 String[] num = {"零","壹","貳","叄","肆","伍","陸","柒","捌","玖"}; //單位 String[] unit = {"","拾","佰","仟","萬","拾","佰","仟","億","拾","佰","仟","萬億"}; //將輸入數字轉換爲字符串 String result[] = String.valueOf(number).split("\\."); //將該字符串分割爲數組存放 char[] ch = result[0].toCharArray(); //結果 字符串 String str = ""; int length = ch.length; for (int i = 0; i < length; i++) { int c = (int)ch[i]-48; if(c != 0) { str += num[c]+unit[length-i-1]; } else { //str += num[c]; } } if(result.length==2 && Integer.parseInt(result[1])>0){ str+="點"; char[] ch1 = result[1].toCharArray(); int length1 = ch1.length; for (int i = 0; i < length1; i++) { int c = (int)ch1[i]-48; if(c != 0) { str += num[c]; } else { //str += num[c]; } } } return str; }