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

Dylan Carter
Dylan Carter
1,046 Points

Why would you use parseInt over parseFloat ever?

Was playing around with the console for this video, and when you use parseFloat for a 3.000 or just 3 for example, it just returns 3. when using the typeof command, both parseInt and parseFloat return as a number datatype.

So, why wouldnt it be a good idea if you were writing a program to just have all numbers stored as floats? If its not a decimal, it seems like its just treated as a normal number, but if it does then it displays a decimal number.

1 Answer

Blake Runyon
seal-mask
.a{fill-rule:evenodd;}techdegree
Blake Runyon
Full Stack JavaScript Techdegree Student 7,539 Points

Hey Dylan,

I'm very new to JS so I'm also learning by responding! But I've read that parseInt() can convert Hex Codes into integers. For example:

let num = parseInt("0xD") would return 13.

Where as:

let num = parseFloat("0xD") would return 0.

Beyond that, I would also love to know!

Dylan Carter
Dylan Carter
1,046 Points

yeah, thats a good point. I know very little about the front end stuff like HTML and CSS (sometimes feel like im doing this backwords lol), which is most likely where the hex code comes into play.