Search code examples
androidandroid-edittextintdouble

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!


Solution

  • You have this in n2Var

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

    instead of

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