📅  最后修改于: 2020-10-24 05:32:09             🧑  作者: Mango
JavaScript数字对象使您可以表示数字值。它可以是整数或浮点数。 JavaScript数字对象遵循IEEE标准来表示浮点数。
借助Number()构造函数,可以在JavaScript中创建数字对象。例如:
var n=new Number(value);
如果不能将值转换为数字,则返回可以由isNaN()方法检查的NaN(非数字)。
您也可以直接将数字分配给变量。例如:
var x=102;//integer value
var y=102.7;//floating point value
var z=13e4;//exponent value, output: 130000
var n=new Number(16);//integer value by number object
输出:
102 102.7 130000 16
让我们看一下带有描述的JavaScript数字常量列表。
Constant | Description |
---|---|
MIN_VALUE | returns the largest minimum value. |
MAX_VALUE | returns the largest maximum value. |
POSITIVE_INFINITY | returns positive infinity, overflow value. |
NEGATIVE_INFINITY | returns negative infinity, overflow value. |
NaN | represents “Not a Number” value. |
让我们看一下JavaScript数字方法及其说明的列表。
Methods | Description |
---|---|
isFinite() | It determines whether the given value is a finite number. |
isInteger() | It determines whether the given value is an integer. |
parseFloat() | It converts the given string into a floating point number. |
parseInt() | It converts the given string into an integer number. |
toExponential() | It returns the string that represents exponential notation of the given number. |
toFixed() | It returns the string that represents a number with exact digits after a decimal point. |
toPrecision() | It returns the string representing a number of specified precision. |
toString() | It returns the given number in the form of string. |