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

Function formatCurrency

packages/web/src/lib/utils.ts:520–534  ·  view source on GitHub ↗
(
    amountSmallestUnit: number,
    currency: string,
    options: { minimumFractionDigits?: number } = {},
)

Source from the content-addressed store, hash-verified

518 * amounts (e.g. "$10" instead of "$10.00").
519 */
520export const formatCurrency = (
521 amountSmallestUnit: number,
522 currency: string,
523 options: { minimumFractionDigits?: number } = {},
524): string => {
525 const formatter = new Intl.NumberFormat('en-US', {
526 style: 'currency',
527 currency: currency.toUpperCase(),
528 ...(options.minimumFractionDigits !== undefined && {
529 minimumFractionDigits: options.minimumFractionDigits,
530 }),
531 });
532 const fractionDigits = formatter.resolvedOptions().maximumFractionDigits ?? 2;
533 return formatter.format(amountSmallestUnit / Math.pow(10, fractionDigits));
534}
535
536export const measureSync = <T>(cb: () => T, measureName: string, outputLog: boolean = true) => {
537 const startMark = `${measureName}.start`;

Callers 3

formatPriceFunction · 0.90
InvoiceRowFunction · 0.90
OnlineLicenseCardFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected