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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.