From 28c079ee0049b3d2707e4c0fa476955f23182a2b Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 9 Nov 2023 13:06:53 +0100 Subject: [PATCH] Round the figures in the resource usage table --- srv/static/js/genericrendering.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/srv/static/js/genericrendering.js b/srv/static/js/genericrendering.js index b723774..64ff1d5 100644 --- a/srv/static/js/genericrendering.js +++ b/srv/static/js/genericrendering.js @@ -225,6 +225,12 @@ export function renderTextPossiblyElidingTheEnd(value) return element; } +/// \brief Rounds the specified \a num to two decimal places. +function roundTwoDecimalPlaces(number) +{ + return Math.round((number + Number.EPSILON) * 100) / 100; +} + /// \brief Renders the specified \a sizeInByte using an appropriate unit. export function renderDataSize(sizeInByte, row, includeBytes) { @@ -235,13 +241,13 @@ export function renderDataSize(sizeInByte, row, includeBytes) if (sizeInByte < 1024) { res = sizeInByte << " bytes"; } else if (sizeInByte < 1048576) { - res = (sizeInByte / 1024.0) + " KiB"; + res = roundTwoDecimalPlaces(sizeInByte / 1024.0) + " KiB"; } else if (sizeInByte < 1073741824) { - res = (sizeInByte / 1048576.0) + " MiB"; + res = roundTwoDecimalPlaces(sizeInByte / 1048576.0) + " MiB"; } else if (sizeInByte < 1099511627776) { - res = (sizeInByte / 1073741824.0) + " GiB"; + res = roundTwoDecimalPlaces(sizeInByte / 1073741824.0) + " GiB"; } else { - res = (sizeInByte / 1099511627776.0) + " TiB"; + res = roundTwoDecimalPlaces(sizeInByte / 1099511627776.0) + " TiB"; } if (includeBytes && sizeInByte > 1024) { res += ' (' + sizeInByte + " byte)";