summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/number_utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/lib/utils/number_utils.js')
-rw-r--r--app/assets/javascripts/lib/utils/number_utils.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/assets/javascripts/lib/utils/number_utils.js b/app/assets/javascripts/lib/utils/number_utils.js
index e3500d02a79..f3dedb7726a 100644
--- a/app/assets/javascripts/lib/utils/number_utils.js
+++ b/app/assets/javascripts/lib/utils/number_utils.js
@@ -72,11 +72,13 @@ export function bytesToGiB(number) {
* @returns {String}
*/
export function numberToHumanSize(size) {
- if (size < BYTES_IN_KIB) {
+ const abs = Math.abs(size);
+
+ if (abs < BYTES_IN_KIB) {
return sprintf(__('%{size} bytes'), { size });
- } else if (size < BYTES_IN_KIB * BYTES_IN_KIB) {
+ } else if (abs < BYTES_IN_KIB ** 2) {
return sprintf(__('%{size} KiB'), { size: bytesToKiB(size).toFixed(2) });
- } else if (size < BYTES_IN_KIB * BYTES_IN_KIB * BYTES_IN_KIB) {
+ } else if (abs < BYTES_IN_KIB ** 3) {
return sprintf(__('%{size} MiB'), { size: bytesToMiB(size).toFixed(2) });
}
return sprintf(__('%{size} GiB'), { size: bytesToGiB(size).toFixed(2) });