F
F
FeeFort2022-03-15 20:20:33
Java
FeeFort, 2022-03-15 20:20:33

Why is parseFloat not working properly?

Why is this code not working properly? parseFloat when getting a number from EditText.getText().toString() gives me 0.0 , although if I put just a string (for example, 1.1), everything works fine.

Non-working code:

EditText et = (EditText) findViewById(R.id.EditText1);

String b = et.getText().toString();
float a = Float.parseFloat(b);
    
start.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        TextView text = findViewById(R.id.textView4);
        text.setText(String.valueOf(String.valueOf(a)));
    }
});


I replace it with just a string: and everything works fine. Why so?
float a = Float.parseFloat("1.1");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2022-03-15
@FeeFort

Check what returnset.getText().toString()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question