Horje
What is the use of the parseFloat() function in JavaScript?

The parseFloat() function in JavaScript is used to parse a string and convert it into a floating-point number. It extracts and returns the first numerical value it encounters in the string, ignoring any non-numeric characters that follow.

Syntax:

parseFloat(string)
  • string: The string to be parsed and converted into a floating-point number.

Example: Here, the string "3.14" is passed to the parseFloat() function, which extracts the numerical value 3.14 from the string and returns it as a floating-point number.

Javascript

const str = "3.14";
const num = parseFloat(str);
console.log(num); // Output: 3.14

Output

3.14




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What is local scope in JavaScript? What is local scope in JavaScript?
How to write a switch statement in JavaScript? How to write a switch statement in JavaScript?
What is Global Scope in JavaScipt? What is Global Scope in JavaScipt?
How to check if an object has a specific property in JavaScript? How to check if an object has a specific property in JavaScript?
What is Array.flatMap() in JavaScript? What is Array.flatMap() in JavaScript?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
16