Reputation: 73
I'm trying to create an app that converts celsius to Farhenheit. I want to pass float in .getText() but I'm unable to do so, It is giving me error which say cannot invoke .getText() on the primitive time float. Like I want to take the user input as double and then do the maths calculation. Can you please suggest me the approach to achieve this.
changer = Float.parseFloat(textIn.getText().toString());
textOut.setText(changer);
Upvotes: 1
Views: 263
Reputation: 24181
float celsius = Float.parseFloat(textIn.getText().toString());
float farhenheit = (celsius * 1.8f) + 32.0f;
textOut.setText(""+farhenheit);
in the case of converting from farhenheit to celsius:
case(R.id.radioButton2):
float farhenheit = Float.parseFloat(textIn.getText().toString());
float celsius = (( farhenheit - 32.0f ) x 5.0f ) / 9.0f;
textOut.setText(""+celsius);
break;
NB : you should add break;
at the end of each case
in the switch
bloc
Upvotes: 1
Reputation: 61
i am currently not able to test this but i think this is the answer u need
String text = edittext.gettext.toString()
double f = double.parseDouble(text);
double f2 = do the math to calculate farhenheit
textview.settext(f2.toString())
Upvotes: 0
Reputation: 3256
txtProt = (EditText) findViewById(R.id.Protein);
p = txtProt.getText().toString();
protein = Double.parseDouble(p);
Upvotes: 2
Reputation: 388
First you want edittext.gettext().tostring. And String Convert to double.
Upvotes: 2