The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix number formatting
Tim Wilsonbe090dddec59
diff --git a/apps/web/ui/analytics/analytics-funnel-chart.tsx b/apps/web/ui/analytics/analytics-funnel-chart.tsxindex f1a4115c0c..32a1f1f1e3 100644--- a/apps/web/ui/analytics/analytics-funnel-chart.tsx+++ b/apps/web/ui/analytics/analytics-funnel-chart.tsx@@ -228,8 +228,11 @@ export function AnalyticsFunnelChartInner({);}-const formatPercentage = (value: number) =>- value > 0 && value < 1 ? "< 1" : nFormatter(value, { digits: 2 });+const formatPercentage = (value: number) => {+ return value > 0 && value < 0.01+ ? "< 0.01"+ : nFormatter(value, { digits: 2 });+};const interpolate = (from: number, to: number) => [{ x: 0, y: from },diff --git a/packages/utils/src/functions/nformatter.ts b/packages/utils/src/functions/nformatter.tsindex 019ef186f0..e95164a36f 100644--- a/packages/utils/src/functions/nformatter.ts+++ b/packages/utils/src/functions/nformatter.ts@@ -8,6 +8,13 @@ export function nFormatter(if (opts.full) {return Intl.NumberFormat("en-US").format(num);}++ const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;++ if (num < 1) {+ return num.toFixed(opts.digits).replace(rx, "$1");+ }+const lookup = [{ value: 1, symbol: "" },{ value: 1e3, symbol: "K" },@@ -17,7 +24,6 @@ export function nFormatter({ value: 1e15, symbol: "P" },{ value: 1e18, symbol: "E" },];- const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;var item = lookup.slice().reverse()