Format a decimal number as USD currency with proper formatting including dollar sign, commas for thousands separators, and always displaying 2 decimal places.
Examples:
Input: 1234.5
Output: "$1,234.50"
Explanation: Number formatted with dollar sign, comma separator, and 2 decimal places
Input: -1234.5
Output: "-$1,234.50"
Explanation: Negative number formatted with minus sign before dollar sign
Input: 1000000
Output: "$1,000,000.00"
Explanation: Large number with multiple comma separators and decimal places
Input: 0
Output: "$0.00"
Explanation: Zero formatted with dollar sign and decimal places
Input: 42.567
Output: "$42.57"
Explanation: Number rounded to 2 decimal places
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay October 2026 (Oct 4–15)Sponsored by FLXBL
Contest runs October 4 - 15. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 12 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.