From 5afa5125a1462e7197d0699f80eaed9c59655081 Mon Sep 17 00:00:00 2001 From: xuqinya Date: Wed, 11 Mar 2020 23:38:22 +0800 Subject: [PATCH] HBASE-23967 Improve the accuracy of the method sizeToString --- .../hadoop/hbase/quotas/QuotaSettings.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java index d644753a4793..b51a20d6e0ad 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java @@ -173,12 +173,22 @@ protected String ownerToString() { } protected static String sizeToString(final long size) { - if (size >= (1L << 50)) return String.format("%dP", size / (1L << 50)); - if (size >= (1L << 40)) return String.format("%dT", size / (1L << 40)); - if (size >= (1L << 30)) return String.format("%dG", size / (1L << 30)); - if (size >= (1L << 20)) return String.format("%dM", size / (1L << 20)); - if (size >= (1L << 10)) return String.format("%dK", size / (1L << 10)); - return String.format("%dB", size); + if (size >= (1L << 50)) { + return String.format("%.2fP", (double)size / (1L << 50)); + } + if (size >= (1L << 40)) { + return String.format("%.2fT", (double)size / (1L << 40)); + } + if (size >= (1L << 30)) { + return String.format("%.2fG", (double)size / (1L << 30)); + } + if (size >= (1L << 20)) { + return String.format("%.2fM", (double)size / (1L << 20)); + } + if (size >= (1L << 10)) { + return String.format("%.2fK", (double)size / (1L << 10)); + } + return String.format("%.2fB", (double)size); } protected static String timeToString(final TimeUnit timeUnit) {