📅  最后修改于: 2020-12-18 05:01:33             🧑  作者: Mango
Number对象代表数字日期,可以是整数,也可以是浮点数。通常,您无需担心Number对象,因为浏览器会自动将数字字面量转换为数字类的实例。
创建数字对象的语法如下-
var val = new Number(number);
如果您提供数字非数字参数,那么该数字将不能转换为数字,而是返回NaN (非数字)。
这是每个属性及其说明的列表。
Sr.No. | Property & Description |
---|---|
1 | MAX_VALUE
The largest possible value a number in JavaScript can have 1.7976931348623157E+308 |
2 | MIN_VALUE
The smallest possible value a number in JavaScript can have 5E-324 |
3 | NaN
Equal to a value that is not a number. |
4 | NEGATIVE_INFINITY
A value that is less than MIN_VALUE. |
5 | POSITIVE_INFINITY
A value that is greater than MAX_VALUE |
6 | prototype
A static property of the Number object. Use the prototype property to assign new properties and methods to the Number object in the current document |
7 | constructor
Returns the function that created this object’s instance. By default this is the Number object. |
在以下各节中,我们将通过一些示例来演示Number的属性。
Number对象仅包含默认方法,这些方法是每个对象定义的一部分。
Sr.No. | Method & Description |
---|---|
1 | toExponential()
Forces a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation. |
2 | toFixed()
Formats a number with a specific number of digits to the right of the decimal. |
3 | toLocaleString()
Returns a string value version of the current number in a format that may vary according to a browser’s local settings. |
4 | toPrecision()
Defines how many total digits (including digits to the left and right of the decimal) to display of a number. |
5 | toString()
Returns the string representation of the number’s value. |
6 | valueOf()
Returns the number’s value. |
在以下各节中,我们将通过一些示例来解释Number的方法。