JavaScript parseFloat: Convert String to Float Number

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.

This Javascript tutorial will demonstrate JavaScript parseFloat () function for convert string to float number; So 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.

Convert a String to float Number in javascript

  • About JavaScript parseFloat() Function
  • JavaScript parseFloat() Function Syntax
  • Examples Convert a String to float Number in javascript

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 :

Examples Convert a String to float Number in javascript


 // 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

Recommended JavaScript Tutorials


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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