JavaScript tutorial:
parseFloat method

 

Applies to: Global Object

The parseFloat method is use to get a floating-point number converted from a string

Syntax

parseFloat(numstring)

The numstring argument is a string that contains a floating-point number.

Return value

Returns a floating-point number converted from a string

Example

The parseFloat method returns an numerical value equal to the number contained in numstring. If no prefix of numstring can be successfully parsed into a floating-point number, NaN (not a number) is returned.

document.write(parseFloat("abc"));// Returns NaN.
document.write(parseFloat("1.2abc"));// Returns 1.2.

You can test for NaN using the isNaN method.

   To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: isNaN Method, parseInt Method, String Object