Search code examples
javaandroidparsingandroid-edittextdouble

How to get double from EditText the right way?


Does anyone know how to parse a double from an EditText?

I know how to do it, but it isn't the right way I think. Does anyone have best practises?

Thank you.


Solution

  • you can try this:

    double value;
    String text =your_edittext.getText().toString();
    if(!text.isEmpty())
    try
    {
       value= Double.parseDouble(text);
       // it means it is double
    } catch (Exception e1) {
       // this means it is not double 
       e1.printStackTrace();
    }