I have a list of many double elements which contains for example the following elements: [1.95, 1.986, 1.9602, 2.0477,...
I tried to use this code to round the elements to two numbers of decimal places:
List<double> listMax = List.from(data_snap()['animals']); //from Firebase
for (var value in listMax) {
value = roundDouble(value,2);
}
double roundDouble(double value, int places){
double mod = pow(10.0, places);
return ((value * mod).round().toDouble() / mod);
}
And as an alternative:
listMax.forEach((element) => roundDouble(element,2));
But both codes are not successful.