通用代码

针对ocr结果处理税率的办法

public static String convertToDecimalString(String percentageString) {
    if("0%".equals(percentageString)){
        return "0.00";
    }
    if ("不征税".equals(percentageString)) {
        return "0.00";
    } else if (percentageString.contains("%")) {
        String numberString = percentageString.replace("%", "");
        double percentage = Double.parseDouble(numberString) / 100;
        DecimalFormat decimalFormat = new DecimalFormat("#0.###");
        String decimalString = decimalFormat.format(percentage);
        if (decimalString.endsWith("0")) {
            decimalString = decimalString.substring(0, decimalString.length() - 1);
        }
        return decimalString;
    } else {
        return percentageString;
    }
}

public static void main(String[] args) {
    String taxRates="6%,3%,13%,9%,5%,1%,17%,11%,,0.06,0.16,17,3,6,5,11,0.17,0.6,0.11,0.3,0.05,0.03,0.10,16%,10%,0.13,0.09,0.1,0.99,0.68,0.69,0.01,0.060,0.130,0.090,0.94,0.98,0.65,0.04,0.66,-0.03,-0.01,0.60,0.39,0.61,0.12,0.64,-0.06,0.07,0.00,0.44,0.90,0.15,0.14,0.59,0.41,0.19,0.5%,1.5%,0%,0,不征税";
    String[] taxRateList= taxRates.split(",");
    for(String taxRate:taxRateList){
        String decimalString = convertToDecimalString(taxRate);
        System.out.println(taxRate+"->"+decimalString);
    }

}