mirror of
https://github.com/localsend/localsend.git
synced 2026-08-07 07:14:52 +00:00
feat: change file size calculation to decimal
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user