我的程序崩溃并关闭到出现的特定页面。 在 LogCat 中,第 19、82 行似乎有问题 解决办法是什么?!
public double format ( double value) {
if ( value != 0){
DecimalFormat df = new DecimalFormat("###.#");
return valueOf(df.format(value));
} else {
return -1;
}
}
和
public double getBMIKg(double height, double weight) {
double meters = height/100;
return format( weight / Math.pow(meters,2));
}
最佳答案
试试这个:
public double getBMIKg(double height, double weight) {
double meters = height/100.0;
double res=meters!=0?weight / Math.pow(meters,2):0
return format(res);
}
关于java - DecimalFormat 和 Math.pow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46100963/