JavaScript parseFloat: Convert String to Float Number

JavaScript parseFloat: Convert String to Float Number

JavaScript parseFloat Function

While working with numbers and decimal point numbers in javascript, it is necessary to know what you can do with them, but the most important thing is how to do it.

In this Javascript tutorial, we will discuss about the javaScript parseFloat () function, you will learn what is parseFloat in javascript and what it does. You will learn from this javascript parseFloat example. After finishing this quick guide, you will be familiar with JavaScript Parsing () syntax and where you should use it.

Learn more javascript parseFloat ()

  • About JavaScript parseFloat() Function
  • JavaScript parseFloat() Function Syntax
  • Example

About JavaScript parseFloat() Function

The javascript parseFloat () function returns an floating point number by parse the string. ParseFloat () Javascript has an inbuilt function.
ParseFloat is accept the string and convert it to a floating point number. If there is not put the value in this function, this is gives return NAN.

JavaScript parseFloat() Function Syntax

The syntax of javascript parseFloat () is very simple. The JavaScript parseFloat () should look like this :

  • Params : It accepts a parameter “string value” that contains a string that is changed to floating-point number.

To understand what parseFloat is in JavaScript, it is necessary to see an example. Take a look at this parseFloat function example – where we parse different numbers and strings :



 // return float value
a = parseFloat("  10  ")
document.write('parseFloat("  10  ") = ' +a +"<br>");

b = parseFloat("123abc")
document.write('parseFloat("123abc") = '+b +"<br>");

// returns NaN value
c = parseFloat("abc456")
document.write('parseFloat("abc456") = ' +c +"<br>");

d = parseFloat("3.14")
document.write('parseFloat("3.14") = '+d +"<br>");

// returns only first Number
e = parseFloat("18 2 2019")
document.write('parseFloat("18 2 2019") = ' +e +"<br>");



parseFloat(" 10 ") = 10
parseFloat("123abc") = 123
parseFloat("abc456") = NaN
parseFloat("3.14") = 3.14
parseFloat("18 2 2019") = 18

Leave a Reply

Your email address will not be published. Required fields are marked *