마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

과제, 통화(화폐)변환기 소수점 문제

0 추천

안녕하세요! 안스를 거의 처음 접하는 학생입니다.

이번 과제가 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...");
        }
    }

}

위 식에서 어떻게 바꿔야 할까요?ㅠㅠ 도와주세요

뀰깡땡 (120 포인트) 님이 2020년 4월 11일 질문
뀰깡땡님이 2020년 4월 11일 수정

1개의 답변

+1 추천

여기서 과제 질문을  하시면 F 받으실 수 있습니다..

어느정돈 구성하신 듯 하니.. 힌트를 드린다면 

String.format 메소드를 사용 하시면 됩니다.

https://devinside.tistory.com/59

익명사용자 님이 2020년 4월 13일 답변
...