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 Foundations Numbers Operators

Why should I use parseInt ?

Hey,

Why should I use parseInt, where I have to also type the radix, when I can use parseFloat all the time ? parseFloat also works for integers...

Did I miss something ?

3 Answers

Fidel Torres
Fidel Torres
25,286 Points

This is a case in which parseInt is Usable:

var a = parseInt("021354254.021351, 10");
var b = parseFloat("021354254.021351");

If you want to get the integer part without the fraction;

console output:

console.log(a);  //  21354254
console.log(b); //  21354254.021351

Hope this helps!!!

In some cases when you want binary numbers and so on ...

So only if I want to use the radix property ?