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
Post a Comment