@vreippainen/hevy-mcp-server
Version:
A MCP server for Hevy
29 lines • 901 B
JavaScript
/**
* Utility functions for currency formatting
*/
/**
* Formats a number as a currency string
* @param value The number to format
* @param currency The currency code (default: 'USD')
* @param locale The locale to use for formatting (default: 'en-US')
* @returns The formatted currency string
*/
export function formatCurrency(value, currency = 'USD', locale = 'en-US') {
if (!Number.isFinite(value)) {
return '';
}
try {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency,
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(value);
}
catch (error) {
console.error(`Error formatting currency: ${error}`);
// Fallback formatting if Intl.NumberFormat fails
return `${currency} ${value.toFixed(2)}`;
}
}
//# sourceMappingURL=currencyFormatter.js.map