roundToDecimalPlaces static method

double roundToDecimalPlaces(
  1. double number,
  2. int decimalPlaces
)

Round number to specified decimal places

number - The number to round decimalPlaces - Number of decimal places Returns rounded number

Implementation

static double roundToDecimalPlaces(double number, int decimalPlaces) {
  final multiplier = pow(10, decimalPlaces);
  return (number * multiplier).round() / multiplier;
}