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

floating point number?

floating point number?

Hi, one of the steps for this challenge is to convert the string from the users input to a floating point number. Why a floating point number and not an integer? thanks.

1 Answer

Mathias Nicolajsen
Mathias Nicolajsen
3,042 Points

Hello Modestats,
First of, I'm sorry if I don't understand your question precisely.
I think you're asking why it has to be parseFloat instead of parseInt. If it is, it's because you have decimal numbers after the first (example: 15.57 is a decimal number 15 is not) then you have to use parseFloat

So what I mean is:
parseInt is used to none decimal numbers (fx: 1, 7, 10000 or 28345)
parseFloat is used to decimal numbers (fx: 1,5 3,14 634,23 38,32435)

exsample in code:

var number1 = "10";
var number2 = "10.5";
parseInt.number1;
parseFloat.number2;
console.log(number1, number2);

I hope this helped, have a nice day and happy coding! :)

Mathias Nicolajsen
Mathias Nicolajsen
3,042 Points

And if you don't understand my answer, then try take a look at this page :) https://www.w3schools.com/js/js_numbers.asp