呼び出されたカスタム メソッドを使用して EditText 出力をフォーマットするようにアクティビティを変更しましたround
が、結果を EditTexts に設定するメソッドを呼び出すと、次のエラーが表示さ
れますThe method setText(CharSequence) in the type TextView is not applicable for the arguments (double)
。私の質問は、この場合、この関数を2
使用settext
するときに結果をどのように出力するのでしょうか?round
public class CalcResult extends MainActivity
{
EditText result1,result2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
result1 = (EditText)findViewById(R.id.mark1);
result2 = (EditText)findViewById(R.id.mark2);
Intent intent = getIntent();
double mark1 = intent.getDoubleExtra("number1", 0);
double mark2 = intent.getDoubleExtra("number2", 0);
//set the variables on EditTexts like this :
result1 = (EditText)findViewById(R.id.mark1);
result2 = (EditText)findViewById(R.id.mark2);
result1.setText(round(mark1,2));
result2.setText(round(mark2,2));
}
public static double round(double value, int places) {
if (places < 0)
throw new IllegalArgumentException();
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(places, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
}