A checkout page stores prices as whole numbers of cents to avoid rounding errors, and formats them only for display.
Write formatPrice(cents) that returns the amount in dollars as $1,234.56: a $, the whole dollars with a comma between every group of three digits counted from the right, a ., and exactly two digits of cents.
Negative amounts get a - before the $, as in -$0.05. Zero is $0.00.
Input: cents = 123456 Output: "$1,234.56"
1234 dollars get one comma; 56 cents follow the dot.
Input: cents = -5 Output: "-$0.05"
Five cents, negative, with the cents padded to two digits.
-10^12 <= cents <= 10^12cents is a whole number.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #606 Group Digits in a Price. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.