中国語の大文字をアラビア数字に変換

2324 ワード

「壹拾叁億零壹」を「130000001」のコードに変換
コードは次のとおりです.

package com.moneyTransfer.Test;

/**
 * 
 * @author yangjianzhou
 *  0---9999 
 */
public class ChineseToDigital {
	
	private static final String data = " ";
	
	private static final String units = " ";
	
	public static void main(String[] args) {
		System.out.println(getDigital(" "));
	}
	
	public static double getDigital(String chineseMoney){
		
		char units[] = {' ',' '};
		
		int indexY = chineseMoney.indexOf(units[0]);
		
		int indexW = chineseMoney.indexOf(units[1]);
		
		double result = 0.0;
		if(indexY>0){
			String substringY = chineseMoney.substring(0, indexY);
			result = result+Math.pow(10000, 2)*getNumber(substringY);
		}
		
		if(indexW>0){
			String substringW = chineseMoney.substring(indexY, indexW);
			result = result +Math.pow(10000, 1)*getNumber(substringW);
		}
		 if(indexY<0&&indexW<0){
			 String  substringG = chineseMoney;
			 result = result +getNumber(substringG);
		 }
		
		 if(indexW<0&&indexY>0&&indexY<chineseMoney.length()-1){
			 String  substringG = chineseMoney.substring(indexY+1, chineseMoney.length());
			 result = result +getNumber(substringG);
		 }
		
		 if(indexW>0&&indexW<chineseMoney.length()-1){
			 String  substringG = chineseMoney.substring(indexW, chineseMoney.length());
			 result = result +getNumber(substringG);
		 }
		  
		 return result;
		
	}
	
	public static double getNumber(String chineseStr){
		double result = 0;
		for(int i=0;i<chineseStr.length();i++){
			int indexData = data.indexOf(chineseStr.charAt(i));
			int indexUnit = units.indexOf(chineseStr.charAt(i));
			if(indexData>=0){
				result = result +(indexData+1);
			}else if(indexUnit>=0){
				result = result*Math.pow(10, indexUnit+1);
			}
		}
		return result;
	}

}


実行結果は次のとおりです.

1.300000001E9