feat: change file size calculation to decimal

This commit is contained in:
Tien Do Nam
2026-07-31 02:38:06 +02:00
parent 6e990a6f42
commit fdec91960b
@@ -1,14 +1,15 @@
extension IntFileSize on int {
/// Converts the integer representing bytes to a readable string
/// using decimal units (1 KB = 1000 B).
String get asReadableFileSize {
if (this < 1024) {
if (this < 1000) {
return '$this B';
} else if (this < 1024 * 1024) {
return '${(this / 1024).toStringAsFixed(1)} KB';
} else if (this < 1024 * 1024 * 1024) {
return '${(this / (1024 * 1024)).toStringAsFixed(1)} MB';
} else if (this < 1000 * 1000) {
return '${(this / 1000).toStringAsFixed(1)} KB';
} else if (this < 1000 * 1000 * 1000) {
return '${(this / (1000 * 1000)).toStringAsFixed(1)} MB';
} else {
return '${(this / (1024 * 1024 * 1024)).toStringAsFixed(1)} GB';
return '${(this / (1000 * 1000 * 1000)).toStringAsFixed(1)} GB';
}
}
}