java - Why parse int throws exception for decimal numbers? -


if enter number in edittext dont exception. if enter number decimal

java.lang.numberformatexception: invalid int: "55555.96"

the value in string inputamount ok decimal number whereas when parsed int gives error when decimal number. when tried parseint,valueof,long .. in exception.

edittext xml:

<edittext     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/edittext"     android:padding="-11dp"     android:width="300dp"     android:inputtype="numberdecimal"     android:digits="0123456789.00"     android:textsize="34sp"     android:editable="true"     android:layout_below="@+id/listview2"     android:textstyle="bold"     android:maxlength="20"     android:layout_alignparenttop="true"     android:layout_centerhorizontal="true"     android:layout_margintop="163dp"     android:hint="payment"     android:maxwidth="222dp" /> 

code:

 amount=(edittext) findviewbyid(r.id.edittext);  string inputamount = amount.gettext().tostring();  int iii = integer.valueof( inputamount.tostring());  int ii=0;  ii=integer.parseint(inputamount.tostring());  long lg=integer.parseint(inputamount); 

use these lines of code

 amount=(edittext) findviewbyid(r.id.edittext);  string inputamount = amount.gettext().tostring();  if(inputamount.contains("."))  {    float jjj =float.valueof(inputamount.tostring())  }  else  {    int iii = integer.valueof( inputamount.tostring());  } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -