以下の関数は、sharedpreferences、weight、heightから2つの値を取得し、BMIを計算するためにこれらを使用します。 値の内容を出力すると、sharedprefsに入力した値が得られますが私がそれらの除算演算を実行すると、結果として常に0が返されます。 エラーはどこですか?Javaでの除算は常にゼロ(0)になりますか?
public int computeBMI(){
SharedPreferences customSharedPreference = getSharedPreferences(
"myCustomSharedPrefs", Activity.MODE_PRIVATE);
String Height = customSharedPreference.getString("heightpref", "");
String Weight = customSharedPreference.getString("weightpref", "");
int weight = Integer.parseInt(Weight);
int height = Integer.parseInt(Height);
Toast.makeText(CalculationsActivity.this, Height+" "+ Weight , Toast.LENGTH_LONG).show();
int bmi = weight/(height*height);
return bmi;
}
整数の除算をしています。 1.0を掛けて浮動小数点にします。 –