java将小写金额转换为大写的工具类

public class Tool {
    
         private static final String UNIT = "万千佰拾亿千佰拾万千佰拾元角分";
         private static final String DIGIT = "零壹贰叁肆伍陆柒捌玖";
         private static final double MAX_VALUE = 9999999999999.99D;
         public static String change(double v) {
          if (v < 0 || v > MAX_VALUE){
              return "参数非法!";
          }
          long l = Math.round(v * 100);
          if (l == 0){
              return "零元整";
          }
          String strValue = l + "";
          // i用来控制数
          int i = 0;
          // j用来控制单位
          int j = UNIT.length() - strValue.length();
          String rs = "";
          boolean isZero = false;
          for (; i < strValue.length(); i++, j++) {
           char ch = strValue.charAt(i);
           if (ch == ‘0‘) {
            isZero = true;
            if (UNIT.charAt(j) == ‘亿‘ || UNIT.charAt(j) == ‘万‘ || UNIT.charAt(j) == ‘元‘) {
             rs = rs + UNIT.charAt(j);
             isZero = false;
            }
           } else {
            if (isZero) {
             rs = rs + "零";
             isZero = false;
            }
            rs = rs + DIGIT.charAt(ch - ‘0‘) + UNIT.charAt(j);
           }
          }
          if (!rs.endsWith("分")) {
           rs = rs + "整";
          }
          rs = rs.replaceAll("亿万", "亿");
          return rs;
         }
        
         public static void main(String[] args){
             System.out.println(Tool.change(12356789.9845));
         }
}

时间: 2024-08-07 21:18:06

java将小写金额转换为大写的工具类的相关文章

C#:小写金额转换为大写

#region 小写金额转换为大写 public static string CurrToChnNum(double Currnum) { string sResult = ""; if (Math.Abs(Currnum) < 1e-20) return "零圆整"; if (Currnum < 1e-20) sResult = "负"; sResult = sResult + StringToChnNum(Math.Abs(Mat

Oracle 小写金额转换为大写

在开发EBS的合同报表打印的时候需要将小写金额转换为大写. 如下是本人自己写的转换函数. 主要思路:先获取小数点位置,在区分整数与小数点处理,根据位数和数字组合读取金额. 最后再处理特殊显示部分. /******************************************************************* *  FUNCTION get_big_amount 数字金额转换为大写 *  p_amount 输入数据金额 *  返回大写金额,位数 :千亿----厘 ****

人民币 小写金额转换为大写金额

### 人民币 小写金额转换为大写金额 标签(空格分隔): 人民币 小写金额转换为大写金额 --- jsp:```div class="form-group"><label class="col-sm-4 control-label">合计人民币金额(小写):</label><div class="col-sm-7"><input id="totalRmbLower" type=

小写金转换为大写

<body><input type="text" id="txt"/><br/><input type="button" id="ss" value="submit"/><br/><input type="text" id="result"/></body><script typ

汇编-小写字母转换为大写字母

一.实习题目:小写字母转换为大写字母 二.实习目的:  1.掌握分支程序设计方法 2.了解小写字母和大写字母在计算机中的表示方法并显示. 三.代码:   data segment A db 'a'; B db 'z'; C db 00h; bb db 0ah,0dh,'$' string db 0ah,0dh,'The input num is not a case letter','$'; data ends code segment assume DS:data,CS:code star

dp、sp 转换为 px 的工具类

/**     * dp.sp 转换为 px 的工具类     *      * @author fxsky 2012.11.12     *     */     public class DisplayUtil {         /**         * 将px值转换为dip或dp值,保证尺寸大小不变         *          * @param pxValue         * @param scale         *            (DisplayMetric

java关闭资源,自制关闭资源工具类

在网上看到一篇关于关闭资源的正确方式:http://blog.csdn.net/bornforit/article/details/6896775 该博文中的总结: (1)使用finally块来关闭物理资源(非托管资源),保证关闭操作始终会被执行: (2)关闭每个资源之前首先保证引用该资源的引用变量不为null: (3)为每个物理资源使用单独的trycatch块关闭资源,保证关闭资源时引发的异常不会影响其他资源的关闭. 在资源过多的时候,我们要在finally块中写很多的非空判断.以及try-c

[C#]枚举操作(从枚举中获取Description,根据Description获取枚举,将枚举转换为ArrayList)工具类

关键代码: using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; namespace CSharpUtilHelpV2 { /// <summary> /// 基于.NET 2.0的枚举工具类 /// </summary> public static class EnumToolV2

java打开文件夹(含判断操作系统工具类和解压缩工具类)

1.Runtime.getRuntime().exec("explorer D:\\Java"); 2.java.awt.Desktop.getDesktop().open(new File("D:\\Java")); 4.java.awt.Desktop.getDesktop().browse(...) 3. try { String[] cmd = new String[5]; cmd[0] = "cmd"; cmd[1] = "/