我有一项活动,可以将价格与订单数量相加,并且还可以选择在此基础上添加增值税。exvat 价格很好,总是加到小数点后 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())))))))))))))))))))))))))))))))))))))))));
;};;});
}