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);//壹零零捌陆零壹
        }
    }

  • 相关阅读:
    缺席多年的东哥,重回博客了
    使用VMware安装CentOS 7
    Linux CentOS 7 搭建 Tomcat 8 服务器
    海思HI3518EV200+AR0130开发板DIY——前篇
    Keyshot+AD渲染PCB效果图
    ESP8266/ESP32模块晶振频偏调试
    关于摄像头PCB图设计经验谈
    docker容器虚拟化技术
    数据分析章节(一):初始数学之美
    Nginx:反向代理
  • 原文地址:https://www.cnblogs.com/liudongdong666666/p/7811467.html
Copyright © 2011-2022 走看看