我寫了學習java的android計算器,並且在應用程序中出現錯誤。如果我輸入5/3 - 答案是2,但我需要浮動結果(1,6)。我需要改變什麼?Java Android:導致計算器顯示整數(需要float/double)
ArrayList<Float> result = new ArrayList<Float>();
float number1;
float number2;
calcDialogDisplay = (TextView) findViewById(R.id.tvResult);
public void DIVISION(){
number1 = result.get(0);
number2 = result.get(1);
result.removeAll(result);
result.add(number1/number2);
calcDialogDisplay.setText(String.format("%.0f", result.get(0)));
}
請閱讀'String.format'文檔....你只是得到你要求的 - 小數位0 0 – Selvin 2015-02-11 16:45:38