complexTruncate function Null safety

Complex complexTruncate(
  1. Complex val,
  2. int fractionDigits
)

Truncate the real and imaginary part of a imaginary number. This function is very useful for compere two double numbers.

  • val : a Complex value
  • fractionDigits : number of decimal digits

Examples

print(complexTruncate(Complex.ri(1.4747474747474747, 1.4747474747474747), 3));

/* output:
Complex(real: 1.475, imaginary: 1.475);
*/

Implementation

Complex complexTruncate(Complex val, int fractionDigits) {
  return Complex.ri(truncate(val.real, fractionDigits),
      truncate(val.imaginary, fractionDigits));
}