roundTo method

double roundTo([
  1. int fractionDigits = 0
])

Rounds this number to fractionDigits decimal places.

Implementation

double roundTo([int fractionDigits = 0]) {
  if (fractionDigits < 0) {
    throw RangeError.value(
        fractionDigits, 'fractionDigits', 'must not be negative');
  }
  final mod = math.pow(10, fractionDigits).toDouble();
  return (this * mod).round() / mod;
}