array2dTruncateEachElement function

dynamic array2dTruncateEachElement(
  1. Array2d a,
  2. int fractionDigits, {
  3. bool returnNewArray = false,
})

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);
    }
  }
}