阿拉伯数值转中文数值

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String nums[]={"0","1","2","3","4","5","6","7","8","9"};
		String chines[]={"零","一","二","三","四","五","六","七","八","九"};
		String level[]={"十","百","千","万","十","百","千","亿"};
		String string="607030030";
		//不算进制,直接将阿拉伯数值转中文数字
		for (int i = 0; i < nums.length; i++) {
			string=string.replaceAll(nums[i], chines[i]);
		}
		System.out.println(string);
		StringBuffer stringBuffer=new StringBuffer(string);
		//插入十进制单位
		for (int i = 0; i < string.length()-1; i++) {
			stringBuffer.insert(string.length()-1-i, level[i]);
		}
		System.out.println(stringBuffer.toString());
		String temp = new String(stringBuffer.toString());
		//处理零的情况
		while((temp.indexOf("零万")!=-1)||(temp.indexOf("零千")!=-1)||(temp.indexOf("零百")!=-1)||(temp.indexOf("零十")!=-1)||(temp.indexOf("零零")!=-1)){
		   if(temp.indexOf("零千")!=-1){
		   temp = temp.replaceAll("零千","零");
		   }
		   if(temp.indexOf("零百")!=-1){
		   temp = temp.replaceAll("零百","零");
		   }
		   if(temp.indexOf("零十")!=-1){
		   temp = temp.replaceAll("零十","零");
		   }
		   if(temp.indexOf("零零")!=-1){
		   temp = temp.replaceAll("零零","零");
		   }
		  
		  if((temp.indexOf("零万")!=-1)){
		   temp = temp.replaceAll("零万","万");
		  }
		     }
		  //处理个位为零的情况
		  if(temp.lastIndexOf("零")==temp.length()-1){
		   temp = temp.substring(0,temp.length()-1);
		  }
		  System.out.println(temp);
	}


posted @ 2016-09-17 22:56  海的心  阅读(162)  评论(0)    收藏  举报