Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: runtime/bin/vmservice/client/lib/src/app/utils.dart

Issue 342513004: Visual refresh of allocation profile page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice/client/lib/src/app/utils.dart
diff --git a/runtime/bin/vmservice/client/lib/src/app/utils.dart b/runtime/bin/vmservice/client/lib/src/app/utils.dart
index 95dc6b59ffc91ddf4580b02e8bd9fafd0365ca85..a53bd59465ceb659d5c6b001ace7b1e4997873d0 100644
--- a/runtime/bin/vmservice/client/lib/src/app/utils.dart
+++ b/runtime/bin/vmservice/client/lib/src/app/utils.dart
@@ -73,22 +73,23 @@ class Utils {
}
static String formatSize(int bytes) {
+ const int digits = 2;
const int bytesPerKB = 1024;
- const int bytesPerMB = 1024 * bytesPerKB;
- const int bytesPerGB = 1024 * bytesPerMB;
- const int bytesPerTB = 1024 * bytesPerGB;
-
- if (bytes < bytesPerKB) {
- return "${bytes}B";
- } else if (bytes < bytesPerMB) {
- return "${(bytes / bytesPerKB).round()}KB";
- } else if (bytes < bytesPerGB) {
- return "${(bytes / bytesPerMB).round()}MB";
- } else if (bytes < bytesPerTB) {
- return "${(bytes / bytesPerGB).round()}GB";
- } else {
- return "${(bytes / bytesPerTB).round()}TB";
- }
+ const int bytesPerMB = 1024 * bytesPerKB;
+ const int bytesPerGB = 1024 * bytesPerMB;
+ const int bytesPerTB = 1024 * bytesPerGB;
+
+ if (bytes < bytesPerKB) {
+ return "${bytes}B";
+ } else if (bytes < bytesPerMB) {
+ return "${(bytes / bytesPerKB).toStringAsFixed(digits)}KB";
+ } else if (bytes < bytesPerGB) {
+ return "${(bytes / bytesPerMB).toStringAsFixed(digits)}MB";
+ } else if (bytes < bytesPerTB) {
+ return "${(bytes / bytesPerGB).toStringAsFixed(digits)}GB";
+ } else {
+ return "${(bytes / bytesPerTB).toStringAsFixed(digits)}TB";
+ }
}
static String formatTime(double time) {

Powered by Google App Engine
This is Rietveld 408576698