• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

java 搞代码 4年前 (2022-01-05) 54次浏览 已收录 0个评论

这篇文章主要介绍了支票金额大写转换示例(金额大写转换器),需要的朋友可以参考下

代码如下:
import java.util.HashMap;
import java.util.Map;

public class FigureAndChinese2Util {

 // 缓存所有数字的
 private static Map map = new HashMap(
   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 (s来源gao*daima.com搞@代#码网b.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);
 }
}

以上就是支票金额大写转换示例(金额大写转换器)的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:支票金额大写转换示例(金额大写转换器)

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址