Number Object

此页有脚本错误。在网站编辑解决此问题前,你可以查看以上的部分内容。

Number Object

The Number object has properties for numerical constants, such as maximum value, not-a-number, and infinity. You cannot change the values of these properties and you use them as follows:

biggestNum = Number.MAX_VALUE
smallestNum = Number.MIN_VALUE
infiniteNum = Number.POSITIVE_INFINITY
negInfiniteNum = Number.NEGATIVE_INFINITY
notANum = Number.NaN

You always refer to a property of the predefined Number object as shown above, and not as a property of a Number object you create yourself.

The following table summarizes the Number object's properties.

Property Description
MAX_VALUE The largest representable number
MIN_VALUE The smallest representable number
NaN Special "not a number" value
NEGATIVE_INFINITY Special negative infinite value; returned on overflow
POSITIVE_INFINITY Special positive infinite value; returned on overflow

Table 7.2: Properties of Number

The Number prototype provides methods for retrieving information from Number objects in various formats. The following table summarizes the methods of Number.prototype.

Method Description
toExponential Returns a string representing the number in exponential notation.
toFixed Returns a string representing the number in fixed-point notation.
toPrecision Returns a string representing the number to a specified precision in fixed-point notation.
toSource Returns an object literal representing the specified Number object; you can use this value to create a new object. Overrides the Object.toSource method.
toString Returns a string representing the specified object. Overrides the Object.toString method.
valueOf Returns the primitive value of the specified object. Overrides the Object.valueOf method.

Table 7.3: Methods of Number.prototype

{{ PreviousNext("Core_JavaScript_1.5_Guide:Predefined_Core_Objects:Math_Object", "Core_JavaScript_1.5_Guide:Predefined_Core_Objects:RegExp_Object") }}

{{ languages( { "es": "es/Gu\u00eda_JavaScript_1.5/Objetos_base_predefinidos/Objeto_Number", "fr": "fr/Guide_JavaScript_1.5/Objets_pr\u00e9d\u00e9finis/L\'objet_Number", "ja": "ja/Core_JavaScript_1.5_Guide/Predefined_Core_Objects/Number_Object", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/Obiekty_predefiniowane/Obiekt_Number" } ) }}

Document Tags and Contributors

Contributors to this page: Cnmahj
最后编辑者: Cnmahj,