somone playsmc
somone playsmc

Reputation: 107

Converting a Edit Text to a double android

I have 2 edit texts and because I want to make them decimals I can not make them integers so I have to turn them into a double. I have this code but in the n2Var get text I have an error.

    mul = (Button) findViewById(R.id.button);
    n1 = (EditText)findViewById(R.id.editText);
    n2 = (EditText)findViewById(R.id.editText2);
    ans = (EditText)findViewById(R.id.TextView10);

    double n1Var = Double.parseDouble(n1.getText().toString());
    double n2Var = Double.parseDouble(n2,getText().toString());

Thanks for any help!

Upvotes: 9

Views: 29228

Answers (2)

Saif Jaradat
Saif Jaradat

Reputation: 171

in Kotlin you can use this..

edittext.text.toString().toDouble()

Upvotes: 7

Inducesmile
Inducesmile

Reputation: 2493

You have this in n2Var

 double n2Var = Double.parseDouble(n2,getText().toString());

instead of

 double n2Var = Double.parseDouble(n2.getText().toString());

Upvotes: 15

Related Questions