NumberFormatException - Android

谁都会走 提交于 2019-12-02 12:34:48

I'd say it's got to do with localization, with . not being the decimal separator in the platforms where the error occurs. Why don't you use a less expensive method of rounding?

public double round(double d, int nDecimals)
{
    for(int i=0; i<nDecimals; ++i) d *= 10d;
    d=Math.round(d);
    for(int i=0; i<nDecimals; ++i) d /= 10d;
    return d;
}

use try catch block to handle it.

Perhaps the error occurs when someone from the Deutsch language uses your application. I've had this problem. They use a comma in place of a decimal (',' instead of '.'). This has thrown me off multiple times

To debug it, add a ton of System.out.println()'s all over your code that spit out a variable when it is changed. These are easier than tools like gdb.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!