humanize method

String humanize({
  1. int precision = 2,
})

Human-readable bit format (e.g., "8 Kb", "1.5 Mb").

Implementation

String humanize({int precision = 2}) {
  final bits = _converter.bits;
  if (bits < BigInt.from(1000)) {
    return '$bits b';
  } else if (bits < BigInt.from(1000000)) {
    return '${(bits.toDouble() / 1000).toStringAsFixed(precision)} Kb';
  } else if (bits < BigInt.from(1000000000)) {
    return '${(bits.toDouble() / 1000000).toStringAsFixed(precision)} Mb';
  } else if (bits < BigInt.from(1000000000000)) {
    return '${(bits.toDouble() / 1000000000).toStringAsFixed(precision)} Gb';
  } else {
    return '${(bits.toDouble() / 1000000000000).toStringAsFixed(precision)} Tb';
  }
}