array2dTruncateEachElement function
dynamic
array2dTruncateEachElement(})
Truncate all the elements of the array
Examples
var a = Array2d([
Array([2.123456789, 2.123456789, 2.123456789]),
Array([2.123456789, 2.123456789, 2.123456789]),
Array([2.123456789, 2.123456789, 2.123456789])
]);
print(array2dTruncateEachElement(a, 4));
/* expected output:
Array2d([
Array([2.1235, 2.1235, 2.1235]),
Array([2.1235, 2.1235, 2.1235]),
Array([2.1235, 2.1235, 2.1235])
]);
*/
Implementation
dynamic array2dTruncateEachElement(Array2d a, int fractionDigits,
{bool returnNewArray = false}) {
if (returnNewArray) {
var b = Array2d.empty();
for (var elem in a) {
var tmp =
arrayTruncateEachElement(elem, fractionDigits, returnNewArray: true);
b.add(tmp);
}
return b;
} else {
for (var elem in a) {
arrayTruncateEachElement(elem, fractionDigits);
}
}
}