java将数字转化为大写方法

    // 日期转化为大小写  
        public static String dataToUpper(String dateStr) {  
            String res="";  
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");  
            Date date = null;  
            try {  
                date = df.parse(dateStr);  
            } catch (Exception e) {  
                // 日期型字符串格式错误  
                System.out.println("日期型字符串格式错误");  
            }  
            if(date!=null){  
                Calendar ca = Calendar.getInstance();  
                ca.setTime(date);  
                int year = ca.get(Calendar.YEAR);  
                int month = ca.get(Calendar.MONTH) + 1;  
                int day = ca.get(Calendar.DAY_OF_MONTH);  
                res=numToUpper(year) + "年" + monthToUppder(month) + "月"+dayToUppder(day) + "日";  
            }  
            return res;  
        }  
      
        // 将数字转化为大写  
        public static String numToUpper(int num) {  
            // String u[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};  
            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 static String monthToUppder(int month) {  
            if (month < 10) {  
                return numToUpper(month);  
            } else if (month == 10) {  
                return "十";  
            } else {  
                return "十" + numToUpper(month - 10);  
            }  
        }  
      
        // 日转化为大写  
        public static String dayToUppder(int day) {  
            if (day < 20) {  
                return monthToUppder(day);  
            } else {  
                char[] str = String.valueOf(day).toCharArray();  
                if (str[1] == '0') {  
                    return numToUpper(Integer.parseInt(str[0] + "")) + "十";  
                } else {  
                    return numToUpper(Integer.parseInt(str[0] + "")) + "十"  
                            + numToUpper(Integer.parseInt(str[1] + ""));  
                }  
            }  
        }  

转自:http://leeleo.iteye.com/blog/1125876
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值