[Contents] [Previous] [Next] [Index]

parseFloat

Parses a string argument and returns a floating point number.

Core function

Implemented in

Navigator 2.0: If the first character of the string specified in parseFloat(string) cannot be converted to a number, returns "NaN" on Solaris and Irix and 0 on all other platforms.

Navigator 3.0, LiveWire 1.0: Returns "NaN" on all platforms if the first character of the string specified in parseFloat(string) cannot be converted to a number.

Syntax

parseFloat(string)

Parameters

string
A string that represents the value you want to parse.

Description

The parseFloat function is a built-in JavaScript function.

parseFloat parses its argument, a string, and returns a floating point number. If it encounters a character other than a sign (+ or -), numeral (0-9), a decimal point, or an exponent, then it returns the value up to that point and ignores that character and all succeeding characters.

If the first character cannot be converted to a number, parseFloat returns "NaN".

For arithmetic purposes, the "NaN" value is not a number in any radix. You can call the isNaN function to determine if the result of parseFloat is "NaN". If "NaN" is passed on to arithmetic operations, the operation results will also be "NaN".

Examples

The following examples all return 3.14:

parseFloat("3.14")
parseFloat("314e-2")
parseFloat("0.0314E+2")
var x = "3.14"
parseFloat(x)
The following example returns "NaN":

parseFloat("FF2")

See also

isNaN, parseInt


[Contents] [Previous] [Next] [Index]

Last Updated: 10/31/97 16:38:00


Copyright © 1997 Netscape Communications Corporation