ITeye博客

金额转换算法[转自csdn]

jackini · 2007-01-22 22:33 · J2EE · Markdown

java 代码

  1. static String t1 = "零壹贰叁肆伍陆柒捌玖";
  2. static char[] n = { '仟', ' ', '拾', '佰' };
  3. static char[] n1 = {'萬','亿'};
  4. static char end = '圆';
  5. public static void print(String value, int pos, boolean b) {
  6. if (pos == 0) {
  7. System.out.print(end);
  8. return;
  9. }
  10. String value2 = value.substring(1, value.length());
  11. int printPos = value.charAt(0) - '0';
  12. if (printPos != 0) {
  13. if (b == true)
  14. System.out.print(t1.charAt(0));
  15. System.out.print(t1.charAt(printPos));
  16. System.out.print(printPos == 0 ? "" : (n[pos % 4] == ' ' ? "": n[pos % 4]));
  17. }
  18. if (pos % 4 == 1 && pos > 1) {
  19. System.out.print(n1[(pos / 4) - 1]);
  20. print(value2, pos - 1,  false);
  21. return;
  22. }
  23. print(value2, pos - 1, printPos == 0 ? true : false);
  24. }

使用方法
print("10010202070", 11, false);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。