Last active
December 4, 2025 17:59
-
-
Save remarkablemark/323e424bab1254db96546b06310a6e2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Formats a number using compact notation with at most one decimal place (e.g., 1.2M or 123K). | |
| * | |
| * @param amount - The number to format. | |
| * @returns The formatted number as a string. | |
| */ | |
| function formatNumber(amount) { | |
| return new Intl.NumberFormat('en-US', { | |
| notation: 'compact', | |
| maximumFractionDigits: 1, | |
| }).format(amount); | |
| } | |
| /** | |
| * Formats a dollar currency with no decimal places (e.g., $123). | |
| * | |
| * @param amount - The number to format. | |
| * @returns The formatted number as a string. | |
| */ | |
| function formatCurrency(amount) { | |
| return new Intl.NumberFormat('en-US', { | |
| style: 'currency', | |
| currency: 'USD', | |
| minimumFractionDigits: 0, | |
| maximumFractionDigits: 0, | |
| }).format(amount); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment