roundABNT static method

double roundABNT(
  1. dynamic num,
  2. dynamic decimalPlaces
)

Implementation

static double roundABNT(num, decimalPlaces) {
  var d = decimalPlaces ?? 0;
  var m = pow(10, d);
  var n = double.parse((num * m).toStringAsFixed(8));
  var i = n.floor();
  var f = n - i;
  var e = 1e-8;
  var r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 == 0) ? i : i + 1) : n.roundToDouble();

  return r / m;
}