Global.parseFloat()

JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, Opera3+ Syntax

paraseFloat(string)

Description

The parseFloat() method is used to convert a string to a number.

Example

Listing 6.140 shows how the parseFloat() is used. In the example, parseFloat is called with two different strings. The first string, which contains numerical characters, is converted to a number without any problems. The second string, which contains alphabetic characters, is unable to be converted into a number.

Listing 6.140 Example of the parseFloat() Method
 <html> <body> <script language="JavaScript"> <!–– Hide // convert the "1245.31" string to a number document.write("The string 1245.31 converted is" + parseFloat("1245.31") ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.