diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 160f89f0c6..0f2538c78f 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -397,10 +397,8 @@ function updateSummaryData(runOnce = false) { intl.format(parseInt(data.clients.total, 10)) + " total clients" ); glowIfChanged($("span#blocked_queries"), intl.format(parseFloat(data.queries.blocked))); - glowIfChanged( - $("span#percent_blocked"), - parseFloat(data.queries.percent_blocked).toFixed(1) + "%" - ); + var formattedPercentage = utils.toPercent(data.queries.percent_blocked, 1); + glowIfChanged($("span#percent_blocked"), formattedPercentage); glowIfChanged( $("span#gravity_size"), intl.format(parseInt(data.gravity.domains_being_blocked, 10)) @@ -536,7 +534,8 @@ $(function () { percentage = (100 * blocked) / (permitted + blocked); } - label += ": " + tooltipLabel.parsed.y + " (" + percentage.toFixed(1) + "%)"; + var formattedPercentage = utils.toPercent(percentage, 1); + label += `: ${tooltipLabel.parsed.y} (${formattedPercentage})`; } else { label += ": " + tooltipLabel.parsed.y; } diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 545545385a..65016d156b 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -378,10 +378,20 @@ function addTD(content) { return "" + content + " "; } +function toPercent(number, fractionDigits = 0) { + const userLocale = navigator.language || "en-US"; + return new Intl.NumberFormat(userLocale, { + style: "percent", + minimumFractionDigits: fractionDigits, + maximumFractionDigits: fractionDigits, + }).format(number / 100); +} + function colorBar(percentage, total, cssClass) { - var title = percentage.toFixed(1) + "% of " + total; - var bar = '
'; - return '
' + bar + "
"; + const formattedPercentage = toPercent(percentage, 1); + const title = `${formattedPercentage} of ${total}`; + const bar = `
`; + return `
${bar}
`; } function checkMessages() {