Section 24.149. parseFloat( ): convert a string to a number


24.149. parseFloat( ): convert a string to a number

ECMAScript v1

24.149.1. Synopsis

 parseFloat(s) 

24.149.1.1. Arguments

s

The string to be parsed and converted to a number.

24.149.1.2. Returns

The parsed number, or NaN if s does not begin with a valid number. In JavaScript 1.0, parseFloat( ) returns 0 instead of NaN when s cannot be parsed as a number.

24.149.2. Description

parseFloat( ) parses and returns the first number that occurs in s. Parsing stops, and the value is returned, when parseFloat( ) encounters a character in s that is not a valid part of the number. If s does not begin with a number that parseFloat( ) can parse, the function returns the not-a-number value NaN. Test for this return value with the isNaN( ) function. If you want to parse only the integer portion of a number, use parseInt( ) instead of parseFloat( ).

24.149.3. See Also

 isNaN( ), parseInt( ) 




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net