hari86
hari86

Reputation: 669

Android: java.lang.NumberFormatException: Invalid int: "1.01"

Hi in my app i am reading the values from the database thru cursor and displaying in textview

my cursor contains the value 1.01 now i wanna display 101 in my text view..doing the following

TextView tv2 = (TextView)view.findViewById(R.id.acValue);

int ach = Integer.parseInt(topcursor.getString(6));

tv2.setText(ach +"");

i am getting the float value as 1.01, now i wanna show the percentage in textview i.e, 101% .how can i do that

But iam getting numberformatexception. Any help is appreciated.

Upvotes: 2

Views: 3561

Answers (5)

krishna
krishna

Reputation: 4089

Using replace() will do the trick

TextView tv2 = (TextView)view.findViewById(R.id.acValue);

int ach = Integer.parseInt(topcursor.getString(6).replace(".", ""));

tv2.setText(ach +"%");

Upvotes: 0

hari86
hari86

Reputation: 669

Thank You all ...Did as follows it work fine..

float ach = Float.parseFloat(topcursor.getString(6));
String kj = String.valueOf(ach*100+"%");

Upvotes: 0

Rethinavel
Rethinavel

Reputation: 3952

There is no need to parse as it returns the string.

TextView tv2 = (TextView)view.findViewById(R.id.acValue);
String mResult  = topcursor.getString(6);
tv2.setText(mResult);

Upvotes: 0

sandy
sandy

Reputation: 3351

Try this

 TextView tv2 = (TextView)view.findViewById(R.id.acValue);

 String ach = topcursor.getString(6);

 tv2.setText(ach);

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157457

1.01 is not an integer value, that is why the conversion is failing. Also be careful with locale when you use the parse* methods

Upvotes: 1

Related Questions