roundTo method

double roundTo(
  1. int decimals
)

Rounds this number to decimals decimal places.

Example:

3.14159.roundTo(2); // 3.14

Implementation

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