Convert the String to a float using JavaScript
In this tutorial, we are going to learn about how to convert the string to a float in JavaScript with the help of examples.
Consider, we have the following string in our code:
const price = "234.123";
Now, we need to convert the above string "234.123"
to a float 234.123
.
Using parseFloat() function
To convert a string to a float, we can use the built-in parseFloat()
function in JavaScript.
The parseFloat()
function takes the string as an argument and parses it to a float point number.
Here is an example:
const price= "234.123";
const result = parseFloat(price);
console.log(result);
Output:
234.123
Additional resources
You can also checkout similar tutorials by reading the following: