I get the wrong output during the collection process

Tags: ,



I made an order application. When I mark the radio buttons, it adds like this, I want it to write normal numbers Screen output like this I don’t want it like this I want it to collect made the sum wrong screen output like this

        boolean checked=((RadioButton) view ).isChecked();
        switch (view.getId()){
            case R.id.rb1:
            if (checked)
                pizza.setPizza_size_price(15);
            break;
            case R.id.rb2:
                pizza.setPizza_size_price(17);
                break;
            case R.id.rb3:
                pizza.setPizza_size_price(19);
                break;
            case R.id.rb6:
                if (checked)
                pizza.setIcecek(3);
                break;
            case R.id.rb7:
                pizza.setIcecek(2);
                break;
            case R.id.rb8:
                pizza.setIcecek(3);
                break;
            case R.id.rb11:
                if (checked)
                pizza.setPatates(5);
                break;
            case R.id.rb12:
                pizza.setPatates(6);
                break;
            case R.id.rb13:
                pizza.setPatates(7);
                break;
        }
        total.setText("Toplam Ücret:"+pizza.getPizza_size_price()+pizza.getIcecek()+pizza.getPatates()+"TL");
    } 

Answer

If your goal is to get the sum of pizza.getPizza_size_price(), pizza.getIcecek() and pizza.getPatates() as output you have to add parenthesis:

total.setText("Toplam Ücret:"+(pizza.getPizza_size_price()+pizza.getIcecek()+pizza.getPatates())+"TL");

Otherwise the numbers won’t be sumed up but just appended to the string like "15.0"+"3.0"+"6.0" which then becomes "15.03.06.0"



Source: stackoverflow