toBKMG method
Bytes → readable size. 1536 → "1.5 KB"
Implementation
String toBKMG() {
if (this <= 0) return "0 B";
const List<String> suffixes = <String>["B", "KB", "MB", "GB", "TB", "PB"];
final int i = this < 1 ? 0 : min((log(this) / log(1024)).floor(), suffixes.length - 1);
final num value = this / pow(1024, i);
return "${i == 0 ? value.round() : value.toStringAsFixed(1)} ${suffixes[i]}";
}