Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Convert String to Number

Numbers, Dates & Timerseasy

Course · Section 12: Numbers, Dates, Intl and Timers · Lecture 181: Converting and Checking Numbers

Implement `toNum(str)` returning the numeric value of a numeric string.

Sample tests

Input: toNum("42")
Output: 42
Input: toNum("3.5")
Output: 3.5

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • parseInt would drop the decimal part.
Approach & explanation (try first)

Number() parses the full numeric value including decimals.

Loading...
⌘/Ctrl + Enter

Run your code to see results.