【发布时间】:2014-04-03 06:02:48
【问题描述】:
我是新来的(确切地说是 5 天),我正在使用 Android 和 Java 制作基本程序。这是我正在处理的代码,我被困在 'else if' on sendAmount() 部分。
我收到一条错误消息,提示“对于参数类型 double、double 的运算符 ^ 未定义”。
现在我的问题是,我怎样才能让它工作并显示结果?
private EditText entPrinAmt;
private EditText entIntRate;
private EditText entTol;
private EditText entMonAmt;
private TextView txtFactor;
private TextView txtFutValue;
private TextView txtIntIncome;
private TextView txtEffRate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
entPrinAmt = (EditText) findViewById(R.id.ent_prin_amt);
entIntRate = (EditText) findViewById(R.id.ent_int_rate);
entTol = (EditText) findViewById(R.id.ent_tol);
entMonAmt = (EditText) findViewById(R.id.ent_mon_amt);
txtFactor = (TextView) findViewById(R.id.txtFactor);
txtFutValue = (TextView) findViewById(R.id.txtFutureVal);
txtIntIncome = (TextView) findViewById(R.id.txtIntIncome);
txtEffRate = (TextView) findViewById(R.id.txtEffRate);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sendAmount(View view) {
DecimalFormat df = new DecimalFormat("#,###,###,###,###,###.##");
DecimalFormat factorFormat = new DecimalFormat("#,###.#####################");
double dPA = Double.parseDouble(entPrinAmt.getText().toString());
double dIR = Double.parseDouble(entIntRate.getText().toString());
double dTL = Double.parseDouble(entTol.getText().toString());
double dMA = Double.parseDouble(entMonAmt.getText().toString());
if (dPA < 0){
Context context = getApplicationContext();
CharSequence txtToast = "Must not be negative!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, txtToast, duration);
toast.show();
}
else if (dPA == 0 && dIR>0 && dTL>0 && dMA>0){
Double resultPA;
resultPA = ((dMA * ((1+dIR/12)^dTL-1)/((1+dIR/12)^dTL*dIR/12)),2);
/*String f = df.format(resultPA); <-v-DO NOT MIND THIS
txtFactor.setText("Principal Amount: P" + f);*/
}
else {
Context context = getApplicationContext();
CharSequence txtToast = "Can't Compute Principal Amount!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, txtToast, duration);
toast.show();
}
}
顺便说一句,我从这里得到了这个等式:
return ROUNDOFF((nPmt*((1+nRate/12)^nPer-1) / ((1+nRate/12)^nPer*nRate/12)),2)
我认为这是来自 C 或 C++ 平台。我不明白 ',2' 部分。我如何将它应用到我正在学习的课程中?任何帮助将不胜感激。
【问题讨论】:
标签: java android operators double