支票金额大写转换示例(金额大写转换器)

2022-10-20,,,

复制代码 代码如下:
import java.util.hashmap;
import java.util.map;

public class figureandchinese2util {

 // 缓存所有数字的
 private static map<character, character> map = new hashmap<character, character>(
   10);
 static {
  map.put('1', '壹');
  map.put('2', '贰');
  map.put('3', '叁');
  map.put('4', '肆');
  map.put('5', '伍');
  map.put('6', '陆');
  map.put('7', '柒');
  map.put('8', '捌');
  map.put('9', '玖');
  map.put('0', '零');
 }
 static char[] mode = new char[] { '拾', '佰', '仟' };

 public static void m(string sb) {

  stringbuffer sbf = new stringbuffer();
  string[] sp = sb.split("\\.");
  if (sp.length == 2) {
   m0(sp[0], 0, sbf);
   sbf.append(m2(sp[1]));
  } else
   m0(sb, 0, sbf);
  sbf.append("整");
  system.out.println(sbf);
 }

 /***
  * 切割字符串
  *
  * @param sb
  */
 public static void m0(string sb, int type, stringbuffer sbf) {

  int len = sb.length();
  int b = 0;
  type++;
  if (len >= 4) {
   b = len - 4;
   sbf.insert(0, m1(sb.substring(b), type));
   m0(sb.substring(0, b), type, sbf);
  } else if (len > 0)
   sbf.insert(0, m1(sb, type));
  if ('零' == sbf.charat(0))
   sbf.deletecharat(0);
 }

 /***
  * 处理
  *
  * @param sb
  */
 public static stringbuffer m1(string sb, int type) {

  stringbuffer sbf = new stringbuffer(sb);
  switch (type) {
  case 1:
   sbf.append("圆");
   break;
  case 2:
   sbf.append("万");
   break;
  case 3:
   sbf.append("亿");
   break;
  default:
   break;
  }
  // 开始赋值
  int b = 0;
  char t = 0;
  for (int i = sbf.length() - 2; i >= 0; i--) {
   t = sbf.charat(i);
   sbf.setcharat(i, map.get(t));
   if (i != 0)
    sbf.insert(i, mode[b]);
   b++;
  }
  for (int i = 0; i < sbf.length(); i++) {
   t = sbf.charat(i);
   if (t == '零') {
    t = sbf.charat(i + 1);
    if ('圆' != t && '万' != t && '亿' != t)
     sbf.deletecharat(i + 1);
    else
     sbf.deletecharat(i);
    if (i != 0)
     if (sbf.charat(i - 1) == '零') {
      sbf.deletecharat(i - 1);
      i--;
     }
   }
  }
  if (sbf.length() == 1) {
   if ('圆' != sbf.charat(0))
    sbf.setlength(0);
  }
  return sbf;
 }

 public static stringbuffer m2(string de) {

  if (de.length() > 2)
   de = de.substring(0, 2);
  de = de.replacefirst("00", "");
  stringbuffer sb = new stringbuffer(de);
  if (sb.length() > 0) {
   if (sb.charat(sb.length() - 1) == '0')
    sb.deletecharat(sb.length() - 1);
   sb.setcharat(0, map.get(sb.charat(0)));
   switch (sb.length()) {
   case 1:
    sb.append("角");
    break;
   case 2:
    sb.setcharat(1, map.get(sb.charat(1)));
    if (sb.charat(0) != '零')
     sb.insert(1, '角');
    sb.append("分");
    break;
   default:
    break;
   }
  }
  return sb;
 }

 public static void main(string[] args) {

  string s = "4444444441.23";
  string s1 = "1";
  string s2 = "1000000000.01";
  string s3 = "101010002.11";
  m(s);
  m(s1);
  m(s2);
  m(s3);
 }
}

《支票金额大写转换示例(金额大写转换器).doc》

下载本文的Word格式文档,以方便收藏与打印。