toPrecision static method

String toPrecision(
  1. double value, {
  2. String? withSymbol,
  3. int decimals = 4,
})

Implementation

static String toPrecision(
  double value, {
  String? withSymbol,
  int decimals = 4,
}) {
  final parsed = value
      .toStringAsPrecision(8)
      .toDouble()
      .toStringAsFixed(decimals);
  if ((withSymbol ?? '').isNotEmpty) {
    return '$parsed $withSymbol';
  }
  return parsed;
}