我创建了一个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;