gpt4 book ai didi

java - android:计算双倍百分比?

转载 作者:行者123 更新时间:2023-12-02 12:36:12 24 4
gpt4 key购买 nike

我想计算百分比。但它给了我错误的结果(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。我想计算百分比。

最佳答案

首先,你的数学是错误的。它应该是值/总计*100,而不是值*总计/100。

关于java - android:计算双倍百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45125083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com