我想计算百分比。但它给了我错误的结果(2.78674E7)。
以下是我的代码:
public class DetailActivity extends AppCompatActivity {
private Button btn_pre_payment;
private EditText et_pre_payment;
private double monthlyPayment;
private double allPayment = 139337000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
btn_pre_payment = (Button)findViewById(R.id.bt_prepayment);
et_pre_payment = (EditText)findViewById(R.id.et_prepayment);
btn_pre_payment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(et_pre_payment.getText().length() > 0){
float value = Float.valueOf(et_pre_payment.getText().toString());
if(value >= 10){
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(et_pre_payment.getApplicationWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
**monthlyPayment = (allPayment / 100f) * value;
tvMonthlyPaymentH.setText(String.valueOf(monthlyPayment));
remainderPayment -= monthlyPayment;**
}
} else Toast.makeText(DetailActivity.this, "Low is 10%!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(DetailActivity.this, "Enter value!", Toast.LENGTH_SHORT).show();
}
}
});
}
}
为什么不能计算出正确的结果?它给了我2.78674E7。我想计算百分比。