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 trialgyatmnucla
7,618 PointsWhy 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
25,286 PointsThis 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!!!
Șilinca Alexandru
9,537 PointsIn some cases when you want binary numbers and so on ...
gyatmnucla
7,618 PointsSo only if I want to use the radix property ?
Șilinca Alexandru
9,537 PointsYou can't without parse string. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt