阅读 163

DecimalFormat国际化中的bug

1.错误场景

西班牙客户手机提示系统应用一直重启

2.错误信息

Caused by: java.lang.NumberFormatException: For input string: "0,00"
                                                       at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1306)
                                                       at java.lang.Double.valueOf(Double.java:511)
                                                       at com.ireadygo.app.performance.core.internal.modules.network.MoveAverageStrategy.weakSignalPercent(MoveAverageStrategy.java:57)
                                                       at com.ireadygo.app.performance.core.internal.modules.network.NetworkEngine.createNetworkInfo(NetworkEngine.java:251)
                                                       at com.ireadygo.app.performance.core.internal.modules.network.NetworkEngine.access$500(NetworkEngine.java:35)
                                                       at ....

复制代码

3.定位为DecimalFormat问题(西班牙语使用,分割)

    DecimalFormat df = new DecimalFormat("#.##");
    MoveAverageStrategy(){
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setDecimalSeparator('.');
        df.setDecimalFormatSymbols(dfs);
    }
复制代码

参考:https://stackoverflow.com/questions/3735630/problems-using-decimalformat