java - convert string value in to integer -


how convert string value integer , multiply converted value integer can result 300.00. see example below -

int value = 5; string  str = "60.00 cur"; 

if code these getting error -

float f = new float(app.price.get(position));            double d = f.doublevalue();                  int = (int)d; 

can try following code , see if want? final answer present in variable "result".

string str = "60.00 usd"; int value = 5; string dollarvalue = str.split(" ")[0]; float price = float.parsefloat(dollarvalue ); float result = price * value;  decimalformat df = new decimalformat("#.##"); df.setminimumfractiondigits(2); string resultstring = df.format(result); 

you "numberformatexception" if try parsefloat on str directly contains string usd. here split , take first part.

edit: try newly added code decimalformat , use resultstring purpose.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -