Partager via


Number.parseInvariant Function

Returns a numeric value from a string representation of a number. This function is static and can be called without creating an instance of the object.

var numberVar = Number.parseInvariant(value);

Arguments

Term

Definition

value

A string that represents a whole or floating-point number.

Returns

A floating-point representation of value, if value represents a number; otherwise, NaN (not a number).

Remarks

Use the parseInvariant function to create a numeric value from a string representation of a number. The value argument can contain a decimal point and the "+" and "-" characters to indicate positive and negative, respectively.

The parseInvariant function provides consistent parsing across all types and should be used instead of the similar ECMAScript (JavaScript) parseInt method.

Example

The following example shows how to use the parseInvariant function to create a numeric value from a string representation of a number.

var a = Number.parseInvariant("4");
var b = new Number(2);
var c = Number.parseInvariant("1.53") + a + b;
// View the results: "7.53"
alert(c); 

See Also

Reference

Number Type Extensions

Number Object

isNaN Method

Other Resources

Language Reference