Skip to content

Commit b9e74e0

Browse files
authored
HBASE-23967 Improve the accuracy of the method sizeToString (#1273)
Signed-off-by: Viraj Jasani <vjasani@apache.org> Signed-off-by: Jan Hentschel <jan.hentschel@ultratendency.com>
1 parent 1b163d9 commit b9e74e0

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,22 @@ protected String ownerToString() {
173173
}
174174

175175
protected static String sizeToString(final long size) {
176-
if (size >= (1L << 50)) return String.format("%dP", size / (1L << 50));
177-
if (size >= (1L << 40)) return String.format("%dT", size / (1L << 40));
178-
if (size >= (1L << 30)) return String.format("%dG", size / (1L << 30));
179-
if (size >= (1L << 20)) return String.format("%dM", size / (1L << 20));
180-
if (size >= (1L << 10)) return String.format("%dK", size / (1L << 10));
181-
return String.format("%dB", size);
176+
if (size >= (1L << 50)) {
177+
return String.format("%.2fP", (double)size / (1L << 50));
178+
}
179+
if (size >= (1L << 40)) {
180+
return String.format("%.2fT", (double)size / (1L << 40));
181+
}
182+
if (size >= (1L << 30)) {
183+
return String.format("%.2fG", (double)size / (1L << 30));
184+
}
185+
if (size >= (1L << 20)) {
186+
return String.format("%.2fM", (double)size / (1L << 20));
187+
}
188+
if (size >= (1L << 10)) {
189+
return String.format("%.2fK", (double)size / (1L << 10));
190+
}
191+
return String.format("%.2fB", (double)size);
182192
}
183193

184194
protected static String timeToString(final TimeUnit timeUnit) {

0 commit comments

Comments
 (0)