Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Numbers!
You have completed JavaScript Numbers!
Preview
Learn how to convert a string to a number in JavaScript, using parseFloat(), parseInt(), and the unary plus (+) operator.
Resources
Example parseInt() and parseFloat() Return Values
| Parse Method | Return Value |
|---|---|
| parseInt('11') | 11 |
| parseInt('135px') | 135 |
| parseInt('202.99') | 202 |
| parseInt('Plan 9') | NaN |
| parseFloat('32.50') | 32.50 |
| parseFloat('-273.15°') | -273.15 |
| parseFloat('Absolute zero is -273.15') | NaN |
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
And that if you're dealing with input
that is supposed to be a number,
0:00
it's best to convert strings that contain
numeric characters into real numbers or
0:01
numeric data types.
0:05
JavaScript provides a few ways
to convert strings to numbers.
0:07
One way is with the parseInt method,
which converts a string to an integer.
0:11
An integer is a whole number without a
decimal point, like 1, 5, or negative 233.
0:17
You provide the parseInt method a string
and it returns an integer value.
0:22
This is a good way to solve
the problem with my program.
0:27
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up