我有一個活動將價格與訂單數量相加,並且還可以選擇在其上添加增值稅。價格很好,總是增加到2位小數。但是,當添加增值稅(英國爲20%)時,它最終會超過2位小數。我見過其他的建議,並沒有能夠得到它的工作。任何幫助將不勝感激。我的代碼如下幫助計算和四捨五入到小數點後兩位
editText1 = (EditText) findViewById(R.id.editText1);
editText2 = (EditText) findViewById(R.id.editText2);
editText3 = (EditText) findViewById(R.id.editText3);
editText4 = (EditText) findViewById(R.id.editText4);
editText5 = (EditText) findViewById(R.id.editText5);
editText6 = (EditText) findViewById(R.id.editText6);
editText7 = (EditText) findViewById(R.id.editText7);
editText8 = (EditText) findViewById(R.id.editText8);
editText9 = (EditText) findViewById(R.id.editText9);
editText10 = (EditText) findViewById(R.id.editText10);
editText11 = (EditText) findViewById(R.id.editText11);
editText12 = (EditText) findViewById(R.id.editText12);
editText13 = (EditText) findViewById(R.id.editText13);
editText14 = (EditText) findViewById(R.id.editText14);
editText15 = (EditText) findViewById(R.id.editText15);
editText16 = (EditText) findViewById(R.id.editText16);
editText17 = (EditText) findViewById(R.id.editText17);
editText18 = (EditText) findViewById(R.id.editText18);
editText19 = (EditText) findViewById(R.id.editText19);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (editText19.getText() != null || editText18.getText() != null || editText17.getText() != null || editText16.getText() != null || editText15.getText() != null || editText14.getText() != null || editText13.getText() != null || editText12.getText() != null || editText11.getText() != null || editText10.getText() != null || editText9.getText() != null || editText8.getText() != null || editText7.getText() != null || editText6.getText() != null || editText5.getText() != null || editText4.getText() != null || editText3.getText() != null)
editText2.setText((String.valueOf(11.67 * (Double.parseDouble(editText16.getText().toString())) + ((15.83 * (Double.parseDouble(editText17.getText().toString())) + ((18.33 * (Double.parseDouble(editText18.getText().toString())) + ((18.33 * (Double.parseDouble(editText18.getText().toString())) + ((24.17 * (Double.parseDouble(editText19.getText().toString())) + ((22.36 * (Double.parseDouble(editText15.getText().toString())) + ((4.17 * (Double.parseDouble(editText14.getText().toString())) + ((26.66 * (Double.parseDouble(editText13.getText().toString())) + ((4.17 * (Double.parseDouble(editText12.getText().toString())) + ((30.96 * (Double.parseDouble(editText11.getText().toString())) + ((4.17 * (Double.parseDouble(editText10.getText().toString())) + ((35.26 * (Double.parseDouble(editText9.getText().toString())) + ((4.17 * (Double.parseDouble(editText8.getText().toString())) + ((39.56 * (Double.parseDouble(editText7.getText().toString())) + ((4.17 * (Double.parseDouble(editText6.getText().toString())) + ((9.17 * (Double.parseDouble(editText5.getText().toString())) + ((13.33 * (Double.parseDouble(editText4.getText().toString())) + ((17.20 * (Double.parseDouble(editText3.getText().toString())))))))))))))))))))))))))))))))))))))));
;};;});
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (editText19.getText() != null || editText18.getText() != null || editText17.getText() != null || editText16.getText() != null || editText15.getText() != null || editText14.getText() != null || editText13.getText() != null || editText12.getText() != null || editText11.getText() != null || editText10.getText() != null || editText9.getText() != null || editText8.getText() != null || editText7.getText() != null || editText6.getText() != null || editText5.getText() != null || editText4.getText() != null || editText3.getText() != null)
editText1.setText((String.valueOf(1.2 * ((11.67 * (Double.parseDouble(editText16.getText().toString())) + ((15.83 * (Double.parseDouble(editText17.getText().toString())) + ((18.33 * (Double.parseDouble(editText18.getText().toString())) + ((18.33 * (Double.parseDouble(editText18.getText().toString())) + ((24.17 * (Double.parseDouble(editText19.getText().toString())) + ((22.36 * (Double.parseDouble(editText15.getText().toString())) + ((4.17 * (Double.parseDouble(editText14.getText().toString())) + ((26.66 * (Double.parseDouble(editText13.getText().toString())) + ((4.17 * (Double.parseDouble(editText12.getText().toString())) + ((30.96 * (Double.parseDouble(editText11.getText().toString())) + ((4.17 * (Double.parseDouble(editText10.getText().toString())) + ((35.26 * (Double.parseDouble(editText9.getText().toString())) + ((4.17 * (Double.parseDouble(editText8.getText().toString())) + ((39.56 * (Double.parseDouble(editText7.getText().toString())) + ((4.17 * (Double.parseDouble(editText6.getText().toString())) + ((9.17 * (Double.parseDouble(editText5.getText().toString())) + ((13.33 * (Double.parseDouble(editText4.getText().toString())) + ((17.20 * (Double.parseDouble(editText3.getText().toString())))))))))))))))))))))))))))))))))))))))));
;};;});
}
這引發了一些錯誤。 bd之前的BigDecimal需要a;完成我覺得奇怪的事情。它還爲我提供了一些快速修復,通常爲BigDecimal創建一個字段。 – j1mmyg88
對不起支架後,如果 – Mathroule
你是先生,是一個LEG結束,muchos gracias senor – j1mmyg88