roundTo method

double roundTo(
  1. int decimals
)

Rounds this number to decimals decimal places.

3.14159.roundTo(2) // 3.14

Implementation

double roundTo(int decimals) {
  final factor = math.pow(10, decimals);
  return (this * factor).round() / factor;
}