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 Introducing the Practice

Pavel Senk
Pavel Senk
2,717 Points

Decimal point

Hello,

Regarding this practice JavaScript Math with Number, I would like to ask If the user enters an input value with a decimal point, for example 3.14, How can I convert the decimal point from "," to "." (like a converting string to number) if the user enters this value on numeric keyboard => 3,14 instead 3.14?

Is there any option ?

Thank you.

Daniel Jong
Daniel Jong
11,071 Points

Hi, you can use the parseFloat() and replace() method together to achieve it!

let num1 = "3,14";
let value = parseFloat(num1.replace(",", "."));

By replacing the comma with period, you can then parse the string into a float.

Hope it helps!

1 Answer

Pavel Senk
Pavel Senk
2,717 Points

Many thanks - solved.