roundTo method

double roundTo({
  1. required int fractionDigits,
})

Rounds the number to fractionDigits decimal places.

Example:

12.3456.roundTo(2); // 12.35

Implementation

double roundTo({required int fractionDigits}) {
  if (this == null) return 0.0;
  final factor = pow(10, fractionDigits);
  return (this! * factor).round() / factor;
}