Javatpoint Logo
Javatpoint Logo

JavaScript Number parseFloat() method

The JavaScript number parseFloat() method parses a string argument and converts it into a floating point number. It returns NaN, if the first character of given value cannot be converted to a number.

Syntax

The parseFloat() method is represented by the following syntax:

Parameter

string - It represents the string to be parsed.

Return

A floating point number parsed from the given value.

JavaScript Number parseFloat() method example

Here, we will understand parseFloat() method through various examples.

Example 1

Let's see a simple example of parseFloat() method.

Test it Now

Output:

50
50.25
NaN
50
50.25

Example 2

Let's see an example to add two strings with and without using parseFloat() method.

Test it Now

Output:

Before invoking parseFloat(): 10.4520.55
After invoking parseFloat(): 31

Next TopicJavaScript Math




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA