zoukankan      html  css  js  c++  java
  • 数字转字符串的处理

    /**
     * 一些字符串的处理
     *
     * @author ldd
     *
     */
    public class MyStringUtils {
        
        /**
         * 提供精确的乘法运算。
         *
         * @param v1 被乘数
         * @param v2 乘数
         * @return 两个参数的积
         */
        public static double mul(double v1, double v2) {
            BigDecimal b1 = new BigDecimal(Double.toString(v1));
            BigDecimal b2 = new BigDecimal(Double.toString(v2));
            return b1.multiply(b2).doubleValue();
        }

        /**
         * 将数字转化为大写  
         *
         * @param num
         * @return
         */
        public static String numToUpper(int num) {  
            String u[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};  
            char[] str = String.valueOf(num).toCharArray();  
            String rstr = "";  
            for (int i = 0; i < str.length; i++) {  
                rstr = rstr + u[Integer.parseInt(str[i] + "")];
            }  
            return rstr;  
        }
    }

    //测试
    public class Main {

        public static void main(String[] args) throws Throwable {
        //设置一个随意的Double
        Double dou= 10086.01D;
        //先调用精确算法 计算成整数
        String strMoney = MyStringUtils.numToUpper((int)(MyStringUtils.mul(dou, 100))); //人民币数字转换为大写汉字
        System.out.println(strMoney);//壹零零捌陆零壹
        }
    }

  • 相关阅读:
    BeanFactory – BeanFactory 实现举例?
    核心容器(应用上下文) 模块?
    JSP有哪些内置对象?作用分别是什么?
    Docker 的目的是什么?
    MyBatis 框架适用场合?
    什么是 Spring Boot?
    简述 Mybatis 的插件运行原理,以及如何编写一个插件。
    数据库连接池
    寒假每周总结3
    寒假每日日报20
  • 原文地址:https://www.cnblogs.com/liudongdong666666/p/7811467.html
Copyright © 2011-2022 走看看