by @kodeazy
flutter How to calculate average value of a list?
In this blog we will discuss on how to caliculate the average value in a List
.
To get the average value in a list follow below steps
- Sum all the elements in a List store the result in a variable called
sum
. - Now divide the value inside the
sum
varibale with length of theList
. -
Below is the example program of getting the average of the list.
void main() { int sum=0; var arr = [1,2,3,4,5]; arr.forEach((e) => sum += e); print("Average value is ${sum/arr.length}"); }
Output:
Average value is 3