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

大写数字转换

时间:2014-08-10 15:37:10      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:blog   java   for   ar   div   amp   new   log   

package data;

public class  NumCover{

	private  String[] numArry = {"零", "壹","贰","叁","肆","伍","陆","柒","捌","玖"};
	private String[] unitArry = {"拾", "佰","仟","万","十万","百万","千万","亿","十亿","百亿","千亿"};
	
	public String[] div(double num){
		long zheng = (long)num;
		long xiao = Math.round((num - zheng) * 100);
		return new String[]{String.valueOf(zheng),String.valueOf(xiao)};
	}
	
	public String cover(String numStr){
		String result = "";
		int len = numStr.length();
		for(int i = 0;i<len; i++){
			int num = numStr.charAt(len-1-i)-48;
			int prenum = 0;
			boolean b = false;
			if(i != len-1){
				prenum = numStr.charAt(len-2-i)-48;
			}
			
			if(i!= 0 && num != 0){
				result = numArry[num] + unitArry[i-1] +result;
				b = true;
			}
			else if((prenum != 0 && b) || ((i == 0) && (num !=0)))
			{
				result = numArry[num] + result;
			}
		}
		return result;
	}

}

  

大写数字转换,布布扣,bubuko.com

大写数字转换

标签:blog   java   for   ar   div   amp   new   log   

原文地址:http://www.cnblogs.com/longneo/p/3902782.html

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