Advertisement
amonnoris

format_utils.dart

Oct 5th, 2024
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.51 KB | Source Code | 0 0
  1. // lib/utils/format_utils.dart
  2.  
  3. String formatBytes(int bytes) {
  4.   const int KB = 1024;
  5.   const int MB = KB * 1024;
  6.   const int GB = MB * 1024;
  7.  
  8.   if (bytes >= GB) {
  9.     return '${(bytes / GB).toStringAsFixed(2)} GB';
  10.   } else if (bytes >= MB) {
  11.     return '${(bytes / MB).toStringAsFixed(2)} MB';
  12.   } else if (bytes >= KB) {
  13.     return '${(bytes / KB).toStringAsFixed(2)} KB';
  14.   } else {
  15.     return '$bytes B';
  16.   }
  17. }
  18.  
  19. String formatSpeed(int bytesPerSecond) {
  20.   return '${formatBytes(bytesPerSecond)}/s';
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement