Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Working With Numbers Numbers and Strings

Difference parseInt() and parseFloat()

Hi!

Can anyone explain me the difference between parseInt and parseFloat? Like in what kind of situation should you use each of them?

Thank you very much! :)

3 Answers

parseInt is for converting a non integer number to an int and parseFloat is for converting a non float (with out a decimal) to a float (with a decimal).

If your were to get input from a user and it comes in as a string you can use the parse method to convert it to a number that you can perform calculations on.

Thank you very much! :)

Simon Coates
Simon Coates
28,694 Points

They deal with different types. A good (apparently i wrote 'google' instead of 'good' - undying shame) place to look at the their behavior would be here and here . Includes examples (that demonstrates the kinds of values accepted.) Jeremy Hill is correct obviously, but i was trying to directed you to MDN as it's a pretty good resource. W3C is also pretty good for finding out more about whatever bit of web technology is currently tormenting you.

Thank you, I'm gonna read more about it! :)

parseInt is a method typically used to covert from a number thats not an integer and parseFloat likewise from a non float number to a float

Thanks! :)