JavaScript parseFloat: Convert String to Float Number

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


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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