From c007ebe32672d2804c59e843cbda98f1a836aa8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 12 Dec 2022 12:36:48 -0500 Subject: [PATCH] feat: allow changing fixed param --- public/src/utils.common.js | 6 +++--- public/src/utils.js | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/src/utils.common.js b/public/src/utils.common.js index eecd064bf8..8396ce4bf9 100644 --- a/public/src/utils.common.js +++ b/public/src/utils.common.js @@ -439,15 +439,15 @@ const utils = { return !utils.isAbsoluteUrl(url); }, - makeNumberHumanReadable: function (num) { + makeNumberHumanReadable: function (num, toFixed = 1) { const n = parseInt(num, 10); if (!n) { return num; } if (n > 999999) { - return (n / 1000000).toFixed(1) + 'm'; + return (n / 1000000).toFixed(toFixed) + 'm'; } else if (n > 999) { - return (n / 1000).toFixed(1) + 'k'; + return (n / 1000).toFixed(toFixed) + 'k'; } return n; }, diff --git a/public/src/utils.js b/public/src/utils.js index 77b2377c7f..bcb4bdb98f 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -17,8 +17,9 @@ utils.getLanguage = function () { utils.makeNumbersHumanReadable = function (elements) { elements.each(function () { - $(this) - .html(utils.makeNumberHumanReadable($(this).attr('title'))) + const $this = $(this); + const toFixed = $this.attr('data-toFixed') || 1; + $this.html(utils.makeNumberHumanReadable($(this).attr('title'), toFixed)) .removeClass('hidden'); }); };