zoukankan      html  css  js  c++  java
  • java切割~~百万 十万 万 千 百 十 个 角 分

     /**
         * @param value
         * @return
         */
        @SuppressWarnings("unused")
        public static void convertLoanRMBTable(double value) {
            LoanContractTemplateBean.LoanRMBTable loanRMBTable = new LoanContractTemplateBean.LoanRMBTable();
                    //百万          十万            万                千            百                十            个              角                分
            String million = "",lakh= "",tenThousand= "",thousand="",hundred= "",ten= "",one="",dime= "",cent= "";
            long midVal = (long) (((value+0.000001) * 1000) / 10); //转化成整形
            String valStr = String.valueOf(midVal); //转化成字符串
            //确保字符串长度大于等于2
            if (valStr.length() == 1) {
                valStr = "0" + valStr;
            }
            String head = valStr.substring(0, valStr.length() - 2);//取整数部分
            String rail = valStr.substring(valStr.length() - 2);//取小数部分
            int headLen = head.length();
            dime=rail.charAt(0) + "";
            cent=rail.charAt(1) + "";
            //9000000
            if (headLen < 7) {
                head = "¥" + head;
                int headLen2 = head.length();
                if (headLen2 < 7) {
                    String added = "";
                    for (int i = 0; i < 7 - headLen2; i++) {
                        added += "a";
                    }
                    head = added + head;
                }
                million= head.charAt(0) == 'a' ? "" : head.charAt(0) + "";
                lakh=head.charAt(1) == 'a' ? "" : head.charAt(1) + "";
                tenThousand=head.charAt(2) == 'a' ? "" : head.charAt(2) + "";
                thousand=head.charAt(3) == 'a' ? "" : head.charAt(3) + "";
                hundred=head.charAt(4) == 'a' ? "" : head.charAt(4) + "";
                ten=head.charAt(5) == 'a' ? "" : head.charAt(5) + "";
                one=head.charAt(6) == 'a' ? "" : head.charAt(6) + "";
            } else if (headLen == 7) {
                million= "¥" + head.charAt(0);
                lakh=head.charAt(1) + "";
                tenThousand=head.charAt(2) + "";
                thousand=head.charAt(3) + "";
                hundred=head.charAt(4) + "";
                ten=head.charAt(5) + "";
                one=head.charAt(6) + "";
            }
            System.out.println("百万==="+million+"	十万==="+lakh+"	万==="+tenThousand+"	千==="+thousand+"	百==="+hundred+"	十==="+ten+"	个==="+one+"	角===="+dime+"	分===="+cent);
        }
        //测试
        public static void main(String[] args) {
            convertLoanRMBTable(3225658.25);
        }
  • 相关阅读:
    是否可以从一个静态(static)方法内部发出对非静态 (non-static)方法的调用?
    是否可以继承 String 类?
    如何实现字符串的反转及替换?
    String s = new String(“xyz”);创建了几个字符串对象?
    Serial 与 Parallel GC 之间的不同之处?
    SVG是什么?
    阐述静态变量和实例变量的区别?
    Java 中 ++ 操作符是线程安全的吗?
    什么是 REST / RESTful 以及它的用途是什么?
    WebSQL是HTML 5规范的一部分吗?
  • 原文地址:https://www.cnblogs.com/yy123/p/4244011.html
Copyright © 2011-2022 走看看