我已經創建了Android版採用三路輸入,使計算如何讓一個整數作爲結果
else {
float result1 = (((new Float(input11.getText().toString())
+ new Float(input21.getText().toString()))/2));
float result2 = (new Float(input31.getText().toString());
if(result1<(result2 - 2)) {
result1 = result2-2;
float result=(float) ((new Float(result1)*0.3)+(new Float(result2)*0.7));
vprosvasis.setText(Float.toString(result));
}
else if(result1>(result2 + 2)) {
result1=result2+2;
float result=(float) ((new Float(result1)*0.3)+(new Float(result2)*0.7));
vprosvasis.setText(Float.toString(result));
}
else {
float result = (float) ((((new Float(input11.getText().toString())
+ new Float(input21.getText().toString()))/2)*0.3)
+ (new Float(input31.getText().toString())*0.7));
vprosvasis.setText(Float.toString(result));
}
}
首先應用,我想結果在每一個語句是e.x. 12.35,不12,342323 ... 其次,我得到相同的方式vprosvasis2-vprosvasis7.i想最後的結果,我打印是一個整數,而不是一個浮動..
float vprosvasisFloat = Float.parseFloat(vprosvasis.getText().toString());
float vprosvasisFloat2 = Float.parseFloat(vprosvasis2.getText().toString());
float vprosvasisFloat7 = Float.parseFloat(vprosvasis7.getText().toString());
float vprosvasisFloat5 = Float.parseFloat(vprosvasis6.getText().toString());
float vprosvasisFloat4 = Float.parseFloat(vprosvasis7.getText().toString());
float vprosvasisFloat3 = Float.parseFloat(vprosvasis6.getText().toString());
float vprosvasisFloat6 = Float.parseFloat(vprosvasis5.getText().toString());
float genikosvathmosoik = ((new Float(vprosvasis.getText().toString())
+ new Float(vprosvasis2.getText().toString())
+ new Float(vprosvasis3.getText().toString())
+ new Float(vprosvasis4.getText().toString())
+ new Float(vprosvasis5.getText().toString())
+ new Float(vprosvasis6.getText().toString())
+ new Float(vprosvasis7.getText().toString()))/7);
moria2oik = (((new Float ((genikosvathmosoik*8)+(vprosvasisFloat * 1.3)+(vprosvasisFloat2 * 0.7))*100)));
moria3oik=(((new Float ((genikosvathmosoik*8)+(vprosvasisFloat4 * 1.3)+(vprosvasisFloat3 * 0.7))*100)));
moria5oik=(((new Float ((genikosvathmosoik*8)+(vprosvasisFloat7 *1.3)+(vprosvasisFloat6 * 0.7))*100)));
switch(spinner.getSelectedItemPosition()){
case 0:
show = new AlertDialog.Builder(mContext).setTitle(R.string.app_name)
.setMessage("1o : -\n2o : "
+ moria2oik + "\n3o : "
+ moria3oik + "\n4o : "
+ moria2oik + "\n5o : "
+ moria5oik)
.setPositiveButton("OK", null).show();
break;
感謝隊友!!它工作正常與十進制格式 – 2011-03-04 00:52:35