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 trialnadia
4,386 PointsDifference 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
Jeremy Hill
29,567 PointsparseInt 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.
Simon Coates
28,694 PointsThey 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.
nadia
4,386 PointsThank you, I'm gonna read more about it! :)
itai chiriseri
5,127 PointsparseInt 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
nadia
4,386 PointsThanks! :)
nadia
4,386 Pointsnadia
4,386 PointsThank you very much! :)