Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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";
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