in my Android app I have a set of string array values - tvs[1], tvs[2], tvs3[3], etc., which contain the textview value from a number of Number Pickers. However, I need the Integer value of each of these strings, so I can then multiply this numeric value with the unit cost of various meals. ie 4 x burgers, 3 x chips, etc. How do I go about this process? I've looked at other questions, but can't find the answer. Can anyone suggest a solution? ie int Value = .....(tvs[1]
2 Answers
This is just one of many ways on how to convert a String to int.
int a = Integer.valueOf(string);
15 Comments
user1641906
Thanks - but what is the syntax for using this, say, in a Toast ie using tvs[1]
user1641906
This is what I have at the moment: result.append(tvs[1].getText().toString() + "x" + "\nHaddock(Med) 50Rs"); - but I want to multiply the 50Rs by the integer value from the string array element tvs[1]
Bojan Kseneman
total += Integer.valueOf(tvs[1].getText().toString()) * 50
user1641906
Hi again! Your answer worked prefectly - one more query (final one!) - how do I add the BigDecimal totalamount1 to totalamount+= , as below.
user1641906
BigDecimal bd = new BigDecimal("4.4"); BigDecimal value = new BigDecimal (Integer.valueOf(tvs[1].getText().toString())); BigDecimal totalamount1 = value.multiply(bd); totalamount+= totalamount1;
|