formatShare function

String formatShare(
  1. double part,
  2. double total
)

Formats part as a percentage of total, for example 0.4%.

Implementation

String formatShare(final double part, final double total) {
  if (total <= 0 || part <= 0) {
    return '0%';
  }
  final double percent = part / total * 100;
  return '${percent.toStringAsFixed(percent >= 10 ? 0 : 1)}%';
}