BMIアプリを作ろうとしています。アプリケーションを実行すると、BMI 値が数値で表示されますが、理解できません。Float 型と Double 型の両方を試しましたが、結果は同じです。
例: 身長 (m): 2 体重 (Kg): 100 BMI は次のように表示されます: 25 ではなく2.0E-4
これに影響するコードの部分は次のとおりです。
String editText1= height_field.getText().toString();
String editText2= weight_field.getText().toString();
try { // Parse string to int
double height = Double.parseDouble(editText1);
double weight = Double.parseDouble(editText2);
double bmi_result = (weight/(height*height));
String bmi_text = Double.toString(bmi_result);
display.setText(bmi_text);
System.out.println("OnClick: computeButton is clicked");
}
catch(NumberFormatException nfe) {
alert.show(); // Show error alert