MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / formatCurrency

Function formatCurrency

apps/start/src/hooks/use-numer-formatter.ts:35–71  ·  view source on GitHub ↗
(locale: string)

Source from the content-addressed store, hash-verified

33
34export const formatCurrency =
35 (locale: string) =>
36 (
37 amount: number,
38 options?: {
39 currency?: string;
40 short?: boolean;
41 },
42 ) => {
43 const short = options?.short ?? false;
44 const currency = options?.currency ?? 'USD';
45 if (short) {
46 // Use compact notation for short format (e.g., "73K $")
47 const formatter = new Intl.NumberFormat(locale, {
48 notation: 'compact',
49 minimumFractionDigits: 0,
50 maximumFractionDigits: 1,
51 });
52 const formatted = formatter.format(amount);
53 // Get currency symbol
54 const currencyFormatter = new Intl.NumberFormat(locale, {
55 style: 'currency',
56 currency: currency,
57 minimumFractionDigits: 0,
58 maximumFractionDigits: 0,
59 });
60 const parts = currencyFormatter.formatToParts(0);
61 const symbol =
62 parts.find((part) => part.type === 'currency')?.value || '$';
63 return `${formatted} ${symbol}`;
64 }
65 return new Intl.NumberFormat(locale, {
66 style: 'currency',
67 currency: currency,
68 minimumFractionDigits: 0,
69 maximumFractionDigits: 1,
70 }).format(amount);
71 };
72
73export function useNumber() {
74 const locale = 'en-US';

Callers 1

useNumberFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected