Availability
JavaScript 1.0; JScript 1.0; ECMAScript v1
Synopsis
parseFloat(s)Arguments
s
The
string to be parsed and converted to a number.
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.
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
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( ).
Bugs
NaN is not supported in JavaScript 1.0, so in that
version of the language, parseFloat( ) returns 0
when it cannot parse s. This means that in
JavaScript 1.0, if the return value of parseFloat(
) is 0, you must perform additional tests on
s to determine whether it really
represents the number zero or does not represent a number at all.
See Also
isNaN( ), parseInt( )
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
JavaScript: The Definitive Guide, 4th Edition
By
David Flanagan
Publisher
: O'Reilly
Pub Date
: November 2001
ISBN
: 0-596-00048-0
Pages
: 936
Slots
: 1
This fourth edition of the definitive reference to
JavaScript, a scripting language that can be embedded
directly in web pages, covers the latest version of the
language, JavaScript 1.5, as supported by Netscape 6 and
Internet Explorer 6. The book also provides complete
coverage of the W3C DOM standard (Level 1 and Level 2),
while retaining material on the legacy Level 0 DOM for
backward compatibility.