안녕하세요, 저는 TextView 수준에서 십진법을 적용 할 수있게 만들고 싶습니다. 그러나 어떻게해야 할 지 알 것입니다. 지금은 1을 내고 있지만 1.80을 내고 싶습니다. :)텍스트보기로 소수점을 표시하십시오.
public class Main extends Activity {
int counter;
EditText weight, hours;
TextView amount, level;
Button calcuate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
counter = 0;
weight = (EditText) findViewById(R.id.weight);
hours = (EditText) findViewById(R.id.hours);
amount = (TextView) findViewById(R.id.amount);
level = (TextView) findViewById(R.id.alcohol_level);
calcuate = (Button) findViewById(R.id.calcuate);
final String widmark = getResources().getString(
R.string.widmark);
final String hundra = getResources().getString(
R.string.hundra);
final String cl = getResources().getString(
R.string.cl);
calcuate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Integer wid, mgs;
String w = weight.getText().toString();
String h = hours.getText().toString();
wid = Integer.parseInt(w) * Integer.parseInt(widmark)/Integer.parseInt(hundra);
mgs = Integer.parseInt(cl)/Integer.parseInt(wid.toString())/Integer.parseInt(hundra);
level.setText(mgs.toString());
}
});
}
}
arithmatic을 수행하기 위해 부동 소수점 숫자를 사용하고 원하는 정밀도가 유지되도록 결과의 형식을 지정하려면'DecimalFormat '을 사용해야합니다. – neevek