Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 54s
14 lines
628 B
TypeScript
14 lines
628 B
TypeScript
// src/utils/formatUtils.ts
|
|
|
|
/**
|
|
* Formats a numeric value in cents into a currency string (e.g., $4.99).
|
|
* Handles different locales and currency symbols gracefully.
|
|
*
|
|
* @param amountInCents The amount in cents to format. Can be null or undefined.
|
|
* @returns A formatted currency string (e.g., "$4.99"), or 'N/A' if the input is null/undefined.
|
|
*/
|
|
export const formatCurrency = (amountInCents: number | null | undefined): string => {
|
|
if (amountInCents === null || amountInCents === undefined) return 'N/A';
|
|
|
|
return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amountInCents / 100);
|
|
}; |