I am setting the sum total of all the items in an array to a text view in android.The values contained in the array are all currency values.
@Override
public void afterTextChanged(Editable s) {
int id = 0;
id = (int) itemtotal.getTag();
String itemTot = itemtotal.getText().toString();
if (id >= 0 && id <= totals.size()) {
totals.set(id - 1, itemTot);
double[] doubleList = new double[totals.size()];
double newsum = 0.0d;
for (int i = 0; i < totals.size(); ++i) {
doubleList[i] = Double.parseDouble(totals.get(i));
newsum += (double) Math.round((doubleList[i]) * 100.0) / 100.0;
}
textViewSum.setText(((double) Math.round((newsum * (0.02) + newsum) * 100.0) / 100.0) + "");//set total text to sum
textViewVat.setText(((double) Math.round((newsum * (0.02)) * 100.0) / 100.0) + "");
}
}
So I am basically calculating the sum total and the vat which is 2%.
The code is pretty straightforward, but I am interested in any possible improvement.