中国語大文字変換アラビア数値ツールクラス


中国語大文字変換アラビア数値ツールクラス
  • ネット上では一般的にアラビア数字から中国語への大文字の数字が使われていますが、領収書には中国語数字からアラビア数字への数字はほとんどありません.ツールクラスを書いて、記録してください.

  • ネット上ではアラビア数字から中国語への大文字が一般的だが、領収書に使われているが、中国語数字からアラビア数字への転換はほとんどない.ツールクラスを書いて、記録してください.
    小数点をサポートします(中国語は点です)
    import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.StringUtils;
    public class NumberUtil {
    public static final Map jsMap = new HashMap() {
    	private static final long serialVersionUID = 1915412114033460201L;
    	{
    		put(" ", 0L); put(" ", 1L); put(" ", 2L); put(" ", 3L); put(" ", 4L); put(" ", 5L);
    		put(" ", 6L); put(" ", 7L); put(" ", 8L); put(" ", 9L);
    	}
    };
    
    /**
     *         ,        
     * 

    0 - 9999999999999999.999999~
    ~ ...

    * @param chineseNum * @return */ public static Double chineseNumToDouble(String chineseNum) { if (chineseNum.indexOf(" ") >= 0) { String[] numSource = chineseNum.split(" "); String integerStr = numSource[0]; String decimalStr = numSource[1]; Long integer = chineseNumToLang(integerStr); String doubleStr = integer.toString() + "." + parseDecimal(decimalStr); return Double.parseDouble(doubleStr); } else { Long integer = chineseNumToLang(chineseNum); String doubleStr = integer.toString(); return Double.parseDouble(doubleStr); } } /** * , *

    0 - 9999999999999999
    ~

    * @param chineseNum * @return */ public static long chineseNumToLang(String chineseNum) { long num = 0; if (StringUtils.isNoneBlank(chineseNum)) { chineseNum = chineseNum.replaceAll(" ", "");// num = parseYi(chineseNum); } return num; } /** * * @param decimalSource * @return */ private static String parseDecimal(String decimalSource) { String decimal = ""; for (int i = 0; i < decimalSource.length(); i++) { String sw = decimalSource.substring(i, i + 1); decimal += jsMap.get(sw).toString(); } return decimal; } private static long parseYi(String chineseNum) { if (chineseNum.indexOf(" ") >= 0) { String[] sourceArray = chineseNum.split(" "); String yiSource = sourceArray[0]; String otherSource = (sourceArray.length > 1) ? sourceArray[1] : ""; long yi = StringUtils.isBlank(yiSource) ? 0 : (parseWan(yiSource) * 100000000L); long other = StringUtils.isBlank(otherSource) ? 0 : (parseWan(otherSource)); long total = yi + other; return total; } else { return parseWan(chineseNum); } } private static long parseWan(String wanNum) { if (wanNum.indexOf(" ") >= 0) { String[] sourceArray = wanNum.split(" "); String wanSource = sourceArray[0]; String otherSource = (sourceArray.length > 1) ? sourceArray[1] : ""; long wan = StringUtils.isBlank(wanSource) ? 0 : (parseQian(wanSource) * 10000L); long other = StringUtils.isBlank(otherSource) ? 0 : (parseQian(otherSource)); long total = wan + other; return total; } else { return parseQian(wanNum); } } private static long parseQian(String qianNum) { if (qianNum.indexOf(" ") >= 0) { String[] sourceArray = qianNum.split(" "); String qianSource = sourceArray[0]; String otherSource = (sourceArray.length > 1) ? sourceArray[1] : ""; long qian = StringUtils.isBlank(qianSource) ? 0 : (parseBai(qianSource) * 1000L); long other = StringUtils.isBlank(otherSource) ? 0 : (parseBai(otherSource)); long total = qian + other; return total; } else { return parseBai(qianNum); } } private static long parseBai(String baiNum) { if (baiNum.indexOf(" ") >= 0) { String[] sourceArray = baiNum.split(" "); String baiSource = sourceArray[0]; String otherSource = (sourceArray.length > 1) ? sourceArray[1] : ""; long bai = StringUtils.isBlank(baiSource) ? 0 : (parseShi(baiSource) * 100L); long other = StringUtils.isBlank(otherSource) ? 0 : (parseShi(otherSource)); long total = bai + other; return total; } else { return parseShi(baiNum); } } private static long parseShi(String shiNum) { if (shiNum.indexOf(" ") >= 0) { String[] sourceArray = shiNum.split(" "); String shiSource = sourceArray[0]; String otherSource = (sourceArray.length > 1) ? sourceArray[1] : ""; long shi = StringUtils.isBlank(shiSource) ? 0 : (parseGe(shiSource) * 10L); long other = StringUtils.isBlank(otherSource) ? 0 : (parseGe(otherSource)); long total = shi + other; return total; } else { return parseGe(shiNum); } } private static long parseGe(String geNum) { if (StringUtils.isBlank(geNum)) { return 0; } else { if (geNum.length() > 1) { geNum = geNum.replaceAll(" ", ""); } return jsMap.get(geNum); } } public static void main(String[] args) { System.out.println(Integer.MAX_VALUE); String _1Str = " "; Double _1num = chineseNumToDouble(_1Str); System.out.println(_1num); String _2Str = " "; Double _2num = chineseNumToDouble(_2Str); System.out.println(_2num); String _3Str = " "; Double _3num = chineseNumToDouble(_3Str); System.out.println(_3num); String _4Str = " "; Double _4num = chineseNumToDouble(_4Str); System.out.println(_4num); String _5Str = " "; Double _5num = chineseNumToDouble(_5Str); System.out.println(_5num); }

    }