Skip to content Skip to sidebar Skip to footer

Invalid Double In Converting String To Double

i get a NumberFormatException : invalid double '111,000,000' in this line of code : double SalePotential = Double.valueOf(EtPotential.getText().toString()); in the beginning i've

Solution 1:

Remove "," before parsing

double SalePotential = Double.parseDouble(EtPotential.getText().toString().replace(",", ""));

Update : With proper implementation

double salePotential = 0; // Variable name should start with small letter try {
    salePotential = Double.parseDouble(EtPotential.getText().toString().replace(",", ""));
} catch (NumberFormatException e) {
    // EditText EtPotential does not contain a valid double
}

Happy coding :)

Solution 2:

Use replace function to replace all occurences of ,

String  s= EtPotential.getText().toString();
     s = s.replace(",", ""); 
     try
     {
       double SalePotential = Double.parseDouble(s);
     }catch(NumberFormatException e)
     {
         e.printStackTrace();
     }

Post a Comment for "Invalid Double In Converting String To Double"