Parses a string and returns a floating point number.
parseFloat(string)
| Parameter | Description |
|---|---|
| string | A string that represents a floating point number in fixed or exponential notation. Truncation occurs at a character that is not correct floating point notation. Leading and trailing spaces are legal. |
function p(stuff) {
print("<<<" + stuff + ">>>");
}
var x = parseFloat("3.14");
if (isNaN(x))
p("x is not a number");
else
p("x = " + x);
// <<<x = 3.14>>>
var x = parseFloat("314e-2");
if (isNaN(x))
p("x is not a number");
else
p("x = " + x);
// <<<x = 3.14>>>
var x = parseFloat("0.0314e+2");
if (isNaN(x))
p("x is not a number");
else
p("x = " + x);
// <<<x = 3.14>>>
var x = parseFloat("f0.0314e+2");
if (isNaN(x))
p("x is not a number");
else
p("x = " + x);
// <<<x is not a number>>>