N-R > parseFloat

parseFloat

Syntax

parseFloat(string);

Arguments

string The string to parse and convert to a floating-point number.

Description

Function; converts a string to a floating-point number. The function parses and returns the numbers in the string, until the parser reaches a character that is not a part of the initial number. If the string does not begin with a number that can be parsed, parseFloat returns NaN or 0. White space preceding valid integers is ignored, as are trailing non-numeric characters.

Player

Flash 5 or later.

Example

The following are examples of using parseFloat to evaluate various types of numbers:

parseFloat("-2") returns -2

parseFloat("2.5") returns 2.5

parseFloat("3.5e6") returns 3.5e6, or 3500000

parseFloat("foobar") returns NaN