roundTo function

double roundTo({
  1. required double candidate,
  2. required int? decimals,
})

Rounds a candidate to the specified decimals

Implementation

double roundTo({
  /// The candidate to perform the rounding
  required double candidate,

  /// The number of decimals to round to
  required int? decimals,
}) {
  switch (decimals) {
    case null:
      return candidate;
    case < 1:
      throw ArgumentError('Decimals should be greater than 0');
    default:
      return double.parse((candidate).toStringAsFixed(decimals));
  }
}