Last active
April 21, 2025 17:26
-
-
Save zzpmaster/ec51afdbbfa5b2bf6ced13374ff891d9 to your computer and use it in GitHub Desktop.
convert bytes to kb mb in dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static String formatBytes(int bytes, int decimals) { | |
if (bytes <= 0) return "0 B"; | |
const suffixes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; | |
var i = (log(bytes) / log(1024)).floor(); | |
return ((bytes / pow(1024, i)).toStringAsFixed(decimals)) + | |
' ' + | |
suffixes[i]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks a lot