Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Format numbers larger than 100m
Uku Tahtfb64345e92cb
diff --git a/assets/js/dashboard/number-formatter.js b/assets/js/dashboard/number-formatter.jsindex 8496ab632b..0ecc4373f6 100644--- a/assets/js/dashboard/number-formatter.js+++ b/assets/js/dashboard/number-formatter.js@@ -2,6 +2,7 @@ const THOUSAND = 1000const HUNDRED_THOUSAND = 100000const MILLION = 1000000const HUNDRED_MILLION = 100000000+const BILLION = 1000000000export default function numberFormatter(num) {if (num >= THOUSAND && num < MILLION) {@@ -11,9 +12,9 @@ export default function numberFormatter(num) {} else {return (Math.floor(thousands * 10) / 10) + 'k'}- } else if (num >= MILLION && num < HUNDRED_MILLION) {+ } else if (num >= MILLION && num < BILLION) {const millions = num / MILLION- if (millions === Math.floor(millions)) {+ if (millions === Math.floor(millions) || num >= HUNDRED_MILLION) {return Math.floor(millions) + 'M'} else {return (Math.floor(millions * 10) / 10) + 'M'diff --git a/lib/plausible_web/views/stats_view.ex b/lib/plausible_web/views/stats_view.exindex 8c4511d1dd..7ef8780f7a 100644--- a/lib/plausible_web/views/stats_view.ex+++ b/lib/plausible_web/views/stats_view.ex@@ -27,7 +27,7 @@ defmodule PlausibleWeb.StatsView don >= 1_000_000 && n < 1_000_000_000 ->millions = trunc(n / 100_000) / 10- if millions == trunc(millions) do+ if millions == trunc(millions) || n > 100_000_000 do"#{trunc(millions)}m"else"#{millions}m"diff --git a/test/plausible_web/views/stats_view_test.exs b/test/plausible_web/views/stats_view_test.exsindex 07922bb6c0..908f22b6a1 100644--- a/test/plausible_web/views/stats_view_test.exs+++ b/test/plausible_web/views/stats_view_test.exs@@ -42,5 +42,9 @@ defmodule PlausibleWeb.StatsView.Test dotest "99_999_999 becomes 99.9m" doassert StatsView.large_number_format(99_999_999) == "99.9m"end++ test "101_000_000 becomes 101m" do+ assert StatsView.large_number_format(101_000_000) == "101m"+ endendend