parseFloat()

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

parseFloat(string)

Description

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

Example

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

Listing 6.204 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") + "<br>"); ...

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.