Skip to content

Commit

Permalink
Ensure number formatting is taking place in browser-scope to use clie…
Browse files Browse the repository at this point in the history
…nt- instead of browser-based number localization

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Dec 26, 2021
1 parent c0dcded commit b7c0fcb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
21 changes: 2 additions & 19 deletions api_FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,9 @@
$tmp = explode(" ",$line);

if(($tmp[0] === "domains_being_blocked" && !is_numeric($tmp[1])) || $tmp[0] === "status")
{
$stats[$tmp[0]] = $tmp[1];
continue;
}

if(isset($_GET['summary']))
{
if($tmp[0] !== "ads_percentage_today")
{
$stats[$tmp[0]] = number_format($tmp[1]);
}
else
{
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
}
}
$stats[$tmp[0]] = $tmp[1]; // Expect string response
else
{
$stats[$tmp[0]] = floatval($tmp[1]);
}
$stats[$tmp[0]] = floatval($tmp[1]); // Expect float response
}
$stats['gravity_last_updated'] = gravity_last_update(true);
$data = array_merge($data,$stats);
Expand Down
5 changes: 4 additions & 1 deletion scripts/pi-hole/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ function updateSummaryData(runOnce) {
updateTopLists();
}

var formatter = new Intl.NumberFormat();
//Element name might have a different name to the property of the API so we split it at |
[
"ads_blocked_today|queries_blocked_today",
Expand All @@ -763,7 +764,9 @@ function updateSummaryData(runOnce) {
var apiName = apiElName[0];
var elName = apiElName[1];
var $todayElement = elName ? $("span#" + elName) : $("span#" + apiName);
var textData = idx === 2 && data[apiName] !== "to" ? data[apiName] + "%" : data[apiName];
// Round to one decimal place and format locale-aware
var text = formatter.format(Math.round(data[apiName] * 10) / 10);
var textData = idx === 2 && data[apiName] !== "to" ? text + "%" : text;
if ($todayElement.text() !== textData && $todayElement.text() !== textData + "%") {
$todayElement.addClass("glow");
$todayElement.text(textData);
Expand Down

0 comments on commit b7c0fcb

Please sign in to comment.