Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Money String

Numbers, Dates & Timerseasy

Course · Section 12: Numbers, Dates, Intl and Timers · Lecture 182: Math and Rounding

Implement `toMoney(n)` returning `n` formatted with exactly two decimal places as a string.

Sample tests

Input: toMoney(5)
Output: "5.00"
Input: toMoney(3.1)
Output: "3.10"

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • toFixed returns a string, not a number.
Approach & explanation (try first)

toFixed(2) formats the number to two decimal places as a string.

Loading...
⌘/Ctrl + Enter

Run your code to see results.