0
모든 것이 오류없이 작동하지만 xml에서는 tvfinalgrade가 0.0 ... 두 번 지느러미가 표시되지 않는 이유는 무엇입니까? 나는 tvfin 코드 라인이 어떤 순서로 작성되어야하는지 확신하지만, 나는 그것이 맞지 않다고 가정하고있다. 앱을 시작하면내 코드가 TextView를 올바르게 변경하지 못합니다.
public class GFActivity extends Activity {
public double fin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getfinal);
double q1, q2, ex;
EditText etq1, etq2, eteg;
etq1 = (EditText)findViewById(R.id.editText1);
try{
q1 = Double.parseDouble(etq1.getText().toString());
} catch (NumberFormatException e) {
q1=0;
}
etq2 = (EditText)findViewById(R.id.editText2);
try{
q2 = Double.parseDouble(etq2.getText().toString());
} catch (NumberFormatException e){
q2 = 0;
}
eteg = (EditText)findViewById(R.id.editText3);
try{
ex = Double.parseDouble(eteg.getText().toString());
} catch (NumberFormatException e){
ex = 0;
}
fin = 0.4*q1+0.4*q2+0.2*ex;
if(fin == (int)fin){
System.out.println((int)fin);
}
else{
fin = 0.01*((int)(fin*100));
System.out.println(fin);
}
Button solve = (Button)findViewById(R.id.getfinbutton);
solve.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tvfin= TextView)findViewById(R.id.tvfinalgrade);
tvfin.setText(fin+"");
}
});
}
}
굉장 했어! 94.6을 표시하는 대신 94.6000001을 표시합니다. 이 문제를 어떻게 해결할 수 있습니까? – Wilson
@JesusSqueegee 이것을 시도해보십시오 :'tvfin.setText (String.format ("% .2f", fin));' – Luksprog