[英]DecimalFormat and Math.pow
我的程序崩潰並關閉了隨之而來的特定頁面。 在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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.