Skip to content

Commit

Permalink
Improved Banner Thousands Separator Logic
Browse files Browse the repository at this point in the history
Use `number_format` to generalize inserting the thousands separators.
This fixes formatting for distances over 1 million.

Tested numbers up to 1 billion.

| Old format   | New format     |
|--------------|----------------|
|            1 |              1 |
|        1,000 |          1,000 |
|     1000,000 |      1,000,000 |
|  1000000,000 |  1,000,000,000 |

Fixes #153.

Side notes:

1. We specify "," because the banner is in English. We could load the
   user's locale and use that but that would only make sense if we
   internationalized the whole banner.
2. The web UI doesn't have any thousands separator at all. Easy enough
   to add but ought to be done in a separate PR.
  • Loading branch information
chrisrosset authored and reedy committed Jun 26, 2023
1 parent 2fe24c6 commit 11a6f8d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion badge/banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function renderImage($textLines, $user = false) {
$units = "miles";
}
$flights = sprintf("%s flights", $row["count"]);
$miles = sprintf("%d,%03d %s", $distance / 1000, $distance % 1000, $units);
$miles = sprintf("%s %s", number_format($distance, 0, ".", ","), $units);
$duration = sprintf(
"%d days, %d:%02d hours",
$row["duration"] / 1440,
Expand Down

0 comments on commit 11a6f8d

Please sign in to comment.