halfUp static method

double halfUp(
  1. double value, {
  2. int precision = 2,
})

Rounds halves up (toward positive infinity).

1.5 → 2, 2.5 → 3, -1.5 → -1, -2.5 → -2

Implementation

static double halfUp(double value, {int precision = 2}) {
  final factor = math.pow(10, precision);
  final scaled = value * factor;
  if (scaled >= 0) {
    return (scaled + 0.5).floorToDouble() / factor;
  } else {
    return (scaled + 0.5).ceilToDouble() / factor;
  }
}