formatNumber function

String formatNumber(
  1. double value
)

Formats a computed value the way a calculator display would: 4, not 4.0.

Implementation

String formatNumber(double value) {
  if (value.isNaN || value.isInfinite) return 'Error';
  if (value == value.roundToDouble() && value.abs() < 1e15) {
    return value.toInt().toString();
  }
  return value
      .toStringAsFixed(10)
      .replaceAll(RegExp(r'0+$'), '')
      .replaceAll(RegExp(r'\.$'), '');
}