arrayComplexTruncateEachElement function

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

Truncate all the numbers of the array

Examples

var n = Array([4.123456789, 4.123456789, 4.123456789]);

print(arrayTruncateEachElement(n, 4));

/* expected output:
Array([4.1235, 4.1235, 4.1235])
*/

Implementation

dynamic arrayComplexTruncateEachElement(ArrayComplex a, int fractionDigits,
    {bool returnNewArray = false}) {
  if (returnNewArray) {
    var b = ArrayComplex.fixed(a.length);
    for (var i = 0; i < a.length; i++) {
      b[i] = complexTruncate(a[i], fractionDigits);
    }
    return b;
  } else {
    for (var i = 0; i < a.length; i++) {
      a[i] = complexTruncate(a[i], fractionDigits);
    }
  }
}