toPrecision method

String toPrecision([
  1. int precision = 2
])

Convert the number to a String with the specified precision. If precision is not specified, the default is 2.

Implementation

String toPrecision([int precision = 2]) {
  var result = toStringAsFixed(precision);
  if (result.endsWith('.00')) {
    result = result.substring(0, result.length - 3);
  }
  return result;
}