人民币小写转大写
/* 将小写的账单数字转换为汉语中的繁体数字,精确到五位小数 *Uesr Code */ import java.io.*; public class Test { static String valueList[][] = { { "零" }, { "壹" }, { "贰" }, { "叁" }, { "肆" }, { "伍" }, { "陆" }, { "柒" }, { "捌" }, { "玖" } }; // 数值部分 static String posList[][] = { { "拾" }, { "佰" }, { "仟" }, { "万" }, { "亿" }, { "兆" }, { "吉" }, { "太" } }; // 小数点前 static String dotList[][] = { { "角" }, { "分" }, { "厘" }, { "毫" }, { "微" } }; // 小数点后 public static void main(String[] args) throws IOException // 对IO异常处理 { byte[] b = new byte[255]; System.in.read(b, 0, 50); String buf = new String(b), dotStr = new String(), tempDot = new String(); System.out.print(buf); int len, i, j = 0, tag = 0, k, tag_zero = 0; for (len = 0; buf.charAt(len) != '\0'; len++) ; if (buf.indexOf(".") != -1) { for (int t = len - 3; buf.charAt(t) != '.'; t--) { dotStr = buf.charAt(t) + dotStr; } for (int t = 0; t != dotStr.length(); t++) { tempDot += valueList[(int) (dotStr.charAt(t) - 48)][0] + dotList[t][0]; } for (len = 0; buf.charAt(len) != '.'; len++) ; len += 2; } String outStr = new String(); String buf_num = new String(); String temp = new String(), temp2 = new String(), lastTemp = new String( ""); for (i = len - 3, j = 0, k = 3; i != -1; i--, j++) { tag = 0; lastTemp = ""; if (j % 4 >= 1) temp2 = posList[j % 4 - 1][0]; if ((int) (buf.charAt(i) - 48) == 0 && tag_zero == 1) { temp = ""; temp2 = ""; } else if ((int) (buf.charAt(i) - 48) == 0) { tag_zero = 1; if (j % 4 != 0) temp = valueList[(int) (buf.charAt(i) - 48)][0]; else temp = ""; } else { tag_zero = 0; temp = valueList[(int) (buf.charAt(i) - 48)][0]; } if (j % 4 >= 1) { if ((int) (buf.charAt(i) - 48) == 0) { buf_num = temp + buf_num; } else { buf_num = temp + temp2 + buf_num; } } else { buf_num = temp + buf_num; } if ((j + 1) % 4 == 0 && j >= 4) { buf_num = buf_num + posList[k++][0]; outStr = buf_num + "" + lastTemp + outStr; buf_num = ""; tag = 1; } else if ((j + 1) % 4 == 0 && j < 4) { outStr = buf_num + "" + lastTemp + outStr; buf_num = ""; tag = 1; } } if (tag == 0 && j > 4) { buf_num = buf_num + posList[k][0]; outStr = buf_num + "" + lastTemp + outStr; } else if (tag == 0) { outStr = buf_num + "" + lastTemp + outStr; } System.out.println("\n" + outStr + "圆" + tempDot); } }