By using Number() constructor
In this method, we can use the Number() constructor which is a built-in function in JavaScript to convert a string into a number, including floats. It parses the argument as a float (or integer) and returns the result.
Example:
// Using Number() constructor to convert a string into a float
let stringNumber = "3.14";
let floatNumber = Number(stringNumber);
console.log(floatNumber); // Output: 3.14
Output
3.14
How to convert string into float in JavaScript?
In this article, we will convert a string into a float in Javascript. We can convert a string into a float in JavaScript by using some methods which are described below: