안녕하세요! 안스를 거의 처음 접하는 학생입니다.
이번 과제가 currency converter app을 만드는 것인데 막바지에 소수점 문제가 있습니다.
제가 원하는 소수점 자리는 2자리 입니다. (ex) 123.45, 9.99, 1212.50)
문제는 소수점이 위 사진과 같이 나옵니다. 구글링 해봤는데 제가 해결하기는 기초가 부족해서인지 어렵더라구요;;
public void click_convert (View view)
{
String myText_string = myText.getText().toString();
float initial_lenght,converted_length;
if(flag_convert)
{
if(myText_string.length() !=0) {
initial_lenght = Float.parseFloat(myText_string);
if (RB_from_wons.isChecked()) {
if (RB_to_dollars.isChecked()) {
converted_length = initial_lenght * (float) 0.00;
myText.setText(myText_string + " Wons = " + String.valueOf(converted_length) + " Dollars");
flag_convert = false;
} else if (RB_to_euro.isChecked()) {
converted_length = initial_lenght * (float) 0.00;
myText.setText(myText_string + " Wons = " + String.valueOf(converted_length) + " Euro");
flag_convert = false;
} else if(RB_to_yens.isChecked()) {
converted_length = initial_lenght * (float) 0.09;
myText.setText(myText_string + " Wons = " + String.valueOf(converted_length) + " Yens");
flag_convert = false;
}
else
{
Notice.setText("Please make your choice...");
}
} else if (RB_from_dollars.isChecked()) {
if (RB_to_wons.isChecked()) {
converted_length = initial_lenght * (float) 1212.50;
myText.setText(myText_string + " Dollars = " + String.valueOf(converted_length) + " Wons");
flag_convert = false;
} else if (RB_to_euro.isChecked()) {
converted_length = initial_lenght * (float) 0.91;
myText.setText(myText_string + " Dollars = " + String.valueOf(converted_length) + " Euro");
flag_convert = false;
} else if (RB_to_yens.isChecked()){
converted_length = initial_lenght * (float) 108.44;
myText.setText(myText_string + " Dollars = " + String.valueOf(converted_length) + " Yens");
flag_convert = false;
}
else
{
Notice.setText("Please make your choice...");
}
} else if (RB_from_euro.isChecked()) {
if (RB_to_wons.isChecked()) {
converted_length = initial_lenght * (float) 1326.54;
myText.setText(myText_string + " Euro = " + String.valueOf(converted_length) + " Wons");
flag_convert = false;
} else if (RB_to_dollars.isChecked()) {
converted_length = initial_lenght * (float) 1.09;
myText.setText(myText_string + " Euro = " + String.valueOf(converted_length) + " Dollars");
flag_convert = false;
} else if (RB_to_yens.isChecked()) {
converted_length = initial_lenght * (float) 118.63;
myText.setText(myText_string + " Euro = " + String.valueOf(converted_length) + " Yens");
flag_convert = false;
}
else
{
Notice.setText("Please make your choice...");
}
} else if (RB_from_yens.isChecked()) {
if (RB_to_wons.isChecked()) {
converted_length = initial_lenght * (float) 11.18;
myText.setText(myText_string + " Yens = " + String.valueOf(converted_length) + " Wons");
flag_convert = false;
} else if (RB_to_dollars.isChecked()) {
converted_length = initial_lenght * (float) 0.01;
myText.setText(myText_string + " Yens = " + String.valueOf(converted_length) + " Dollars");
flag_convert = false;
} else if (RB_to_euro.isChecked()) {
converted_length = initial_lenght * (float) 0.01;
myText.setText(myText_string + " Yens = " + String.valueOf(converted_length) + " Euro");
flag_convert = false;
}
else
{
Notice.setText("Please make your choice...");
}
}
else
{
Notice.setText("Please make your choice...");
}
}
else
{
Notice.setText("Please insert an amount...");
}
}
}
위 식에서 어떻게 바꿔야 할까요?ㅠㅠ 도와주세요