码迷,mamicode.com
首页 > 其他好文 > 详细

人民币数字转文字

时间:2015-06-13 20:04:04      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

package day01;

/**
 * Created by sherry on 000019/3/19 14:27.
 */
public class RmbToChar {
    public static void main(String[] args) {
        /*输入要求:10000以内的小数,对于特殊情况未做判断*/
        rmbToChar(15523.451);
    }

    private static void rmbToChar(double v) {
        String num = Double.toString(v);
        /*大写码表*/
        String[] numberMap = {"零","壹","贰","叁","肆","伍","陆","柒","扒","玖"};
        /*整数部分*/
        String integerPart = num.substring(0,num.indexOf("."));
        /*小数部分*/
        String decimalsPart = num.substring(num.indexOf(".")+1);
        System.out.println(integerPart+"."+decimalsPart);

        char[] integerParts = integerPart.toCharArray();
        char[] decimalsParts = decimalsPart.toCharArray();

        for (int i = 0;i < integerParts.length;i++){
            System.out.print(numberMap[Integer.parseInt(String.valueOf(integerParts[i]))]);
            switch (integerParts.length-i){
                case 5:
                    System.out.print("万");
                    break;
                case 4:
                    System.out.print("仟");
                    break;
                case 3:
                    System.out.print("佰");
                    break;
                case 2:
                    System.out.print("拾");
                    break;
                default:
                    System.out.print("元");
            }
        }
        for (int i = 0;i < decimalsParts.length;i++){
            System.out.print(numberMap[Integer.parseInt(String.valueOf(decimalsParts[i]))]);
            switch (i){
                case 0:
                    System.out.print("角");
                    break;
                case 1:
                    System.out.print("分");
                    break;
                case 2:
                    System.out.print("厘");
                    break;
                default:
                    System.out.print("毫");
            }
        }
    }
}

 

人民币数字转文字

标签:

原文地址:http://www.cnblogs.com/sherrykid/p/4573893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!