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 July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.