2
I need to average some numbers I receive via JSON in the format of String
s, this calculation must return a value so that I can set it within a TextView
on Android, but I’m not able to format this answer so it only comes with a decimal (example: the calculation returns 46.7) it’s returning a much higher value:
private Float calculateAverage(Powerstats powerstats) {
float sum;
sum = Float.parseFloat("70" + "26" + "83"
+ "55" + "81" + "69");
return sum / 6;
}
the return of this function should be a number formatted with only 1 decimal place.
This sum of strings there is not doing what you think it is. You know which sign of + does not add strings, and yes CONCATENATE? This is what happens: https://ideone.com/wr1I4D
– user28595