Skip to content

Commit 2efeca4

Browse files
Merge pull request #4552 from rabbitmq/mergify/bp/v3.8.x/pr-4551
SI prefix formatter improvement (backport #4542) (backport #4550) (backport #4551)
2 parents 5bcb12c + e9d1286 commit 2efeca4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

deps/rabbitmq_management/priv/www/js/formatters.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ function fmt_string(str, unknown) {
1919
return fmt_escape_html("" + str);
2020
}
2121

22-
function fmt_si_prefix(num0, max0, thousand, allow_fractions) {
22+
function fmt_si_prefix(num0, max0, binary, allow_fractions) {
2323
if (num == 0) return 0;
2424

25+
var thousand = binary ? 1024 : 1000;
2526
function f(n, m, p) {
2627
if (m > thousand) return f(n / thousand, m / thousand, p + 1);
2728
else return [n, m, p];
@@ -32,8 +33,9 @@ function fmt_si_prefix(num0, max0, thousand, allow_fractions) {
3233
var max = num_power[1];
3334
var power = num_power[2];
3435
var powers = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
36+
var suffix = powers[power] + ((power != 0 && binary) ? 'i' : '');
3537
return (((power != 0 || allow_fractions) && max <= 10) ? num.toFixed(1) :
36-
num.toFixed(0)) + " " + powers[power];
38+
num.toFixed(0)) + " " + suffix;
3739
}
3840

3941
function fmt_boolean(b, unknown) {
@@ -301,7 +303,7 @@ function fmt_plain(num) {
301303
}
302304

303305
function fmt_plain_axis(num, max) {
304-
return fmt_si_prefix(num, max, 1000, true);
306+
return fmt_si_prefix(num, max, false, true);
305307
}
306308

307309
function fmt_rate(num) {
@@ -314,8 +316,8 @@ function fmt_rate_axis(num, max) {
314316

315317
function fmt_bytes(bytes) {
316318
if (bytes == undefined) return UNKNOWN_REPR;
317-
var prefix = fmt_si_prefix(bytes, bytes, 1024, false);
318-
return prefix + (prefix.endsWith(' ') ? 'B' : 'iB');
319+
var prefix = fmt_si_prefix(bytes, bytes, true, false);
320+
return prefix + 'B';
319321
}
320322

321323
function fmt_bytes_axis(num, max) {

0 commit comments

Comments
 (0)