Format Money

75.0% Acceptance

Write a function called formatMoney(amount), which takes in a floating-point number amount as input and returns a string representation of the number formatted as currency. The output string should have the dollar sign "$" and should have two decimal places, even if the input number has fewer decimal places. The output string should also include commas to separate thousands, millions, billions, and so on.


  • The input amount can be negative.

Example test cases

formatMoney(123); // Output: $123.00 formatMoney(0); // Output: $0.00 formatMoney(12.23); // Output: $12.23 formatMoney(123.4123); // Output: $123.41 formatMoney(100000000); // Output: $100,000,000.00