我是新來的人(確切的說是5天)在Android和Java中製作基本程序。以下是我正在處理的代碼,並且我堅持在'else if'on sendAmount()此代碼的一部分。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();
}
}
BTW,我從這裏公式:
回報舍人((nPmt *((1 + nRate/12)^ NPER-1)/((1 + nRate/12)^nPer * nRate/12)),2)
我認爲這是來自C或C++平臺。我不明白',2'部分。我怎樣才能將它應用到我正在學習的課程中?任何幫助將不勝感激。
我真的認爲它的力量..香港專業教育學院今天學到了一些東西,謝謝。 – Daichi