From cbf6240f624666a7acde4ee6d4b0caba5528559e Mon Sep 17 00:00:00 2001 From: gilles Date: Thu, 11 Jul 2013 11:52:41 +0200 Subject: [PATCH] Change pretty print size to display IEC units and use toFixed() instead of round. --- pgbadger | 60 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/pgbadger b/pgbadger index 82a9da3..76305fa 100755 --- a/pgbadger +++ b/pgbadger @@ -6103,7 +6103,7 @@ document.writeln('
= 1000000000) - return Math.round(val / 1000000000) + " GB"; - else if (val >= 1000000) - return Math.round(val / 1000000) + " MB"; - else if (val >= 1000) - return Math.round(val / 1000) + " KB"; - else - return Math.round(val) + " B"; + if (val >= 1125899906842624) { + val = (val / 1125899906842624); + val = val.toFixed(2) + " PiB"; + } else if (val >= 1099511627776) { + val = (val / 1099511627776); + val = val.toFixed(2) + " TiB"; + } else if (val >= 1073741824) { + val = (val / 1073741824); + val = val.toFixed(2) + " GiB"; + } else if (val >= 1048576) { + val = (val / 1048576); + val = val.toFixed(2) + " MiB"; + } else if (val >= 1024) { + val = (val / 1024); + val = val.toFixed(2) + " KiB"; + } else { + val = val + " B"; + } } else { - if (val >= 1000000000000) - return Math.round(val / 1000000000000) + " T"; - else if (val >= 1000000000) - return Math.round(val / 1000000000) + " G"; - else if (val >= 1000000) - return Math.round(val / 1000000) + " M"; - else if (val >= 1000) - return Math.round(val / 1000) + " K"; - else - return Math.round(val); + if (val >= 1000000000000000) { + val = (val / 1000000000000000); + val = val.toFixed(2) + " P"; + } else if (val >= 1000000000000) { + val = (val / 1000000000000); + val = val.toFixed(2) + " T"; + } else if (val >= 1000000000) { + val = (val / 1000000000); + val = val.toFixed(2) + " G"; + } else if (val >= 1000000) { + val = (val / 1000000); + val = val.toFixed(2) + " M"; + } else if (val >= 1000) { + val = (val / 1000); + val = val.toFixed(2) + " K"; + } } return val; } -- 2.40.0