★ wanayoo — archive 1999 http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseFloatNouvelle recherche | Portail wanayoo

Mozilla.com

parseFloat

Summary

Core Function

Parses a string argument and returns a floating point number.

Syntax

parseFloat(string)

Parameters

string 
A string that represents the value you want to parse.

Description

parseFloat is a top-level function and is not associated with any object.

parseFloat parses its argument, a string, and returns a floating point number. If it encounters a character other than a sign (+ or -), numeral (0-9), a decimal point, or an exponent, it returns the value up to that point and ignores that character and all succeeding characters. Leading and trailing spaces are allowed.

If the first character cannot be converted to a number, parseFloat returns NaN.

For arithmetic purposes, the NaN value is not a number in any radix. You can call the isNaN function to determine if the result of parseFloat is NaN. If NaN is passed on to arithmetic operations, the operation results will also be NaN.

Examples

Example: parseFloat returning a number

The following examples all return 3.14:

  • parseFloat("3.14");
  • parseFloat("314e-2");
  • parseFloat("0.0314E+2");
  • var x = "3.14";
    parseFloat(x);
  • parseFloat("3.14more non-digit characters");

Example: parseFloat returning NaN

The following example returns NaN:

  • parseFloat("FF2");

See Also

isNaN, parseInt



Page last modified 07:07, 5 Oct 2007 by Mgjbot

Tags:

Files (0)