Numbers 数字

Numbers are the most basic datatype; All numbers in JavaScript are represented as floating-point values.
数字是最基本的数据类型;在JavaScript中,所有的数字都是由浮点型(floating-point)表示的。

When a nubmer appears directly in a JavaScript program, it’s called a numeric literal.
当一个数字直接出现在JavaScript程序中时,我们称它为数字直接量(numeric literal)。

Integer Literalsˈɪntɪdʒə ˈlitərəl整型直接量

A base-10 integer is written as a sequence of digits.
十进制的整数是一个数字序列。

The JavaScript number format allows you to exactly represent all integers between -9007199254740992 and 9007199254740992, inclusive.
JavaScript数字格式允许精确表示-9007199254740992和9007199254740992之间的所有整数。

Hexadecimal and Octal Literalsheksəˈdesim(ə)l十六进制和八进制ˈɔktl的直接量

A hexadecimal literal begins with “0x” or “0X”, followed by a string of hexadecimal digits.
所谓十六进制(hexadecimal)的直接量,是以“0x”或者“0X”开头,其后跟随十六进制数字串的直接量。

An octal literal begins with the digit 0 and is followed by a sequence of digits, each between 0 and 7.
八进制(octal)的直接量以数字0开头,其后跟随一个数字序列(sequence),这个序列中的每个数字都在0和7之间(包括0和7)。

Floating-Point Literals 浮点型直接量

Floating-Point Literals can have a decimal point; they use the traditional syntax for real numbers.
浮点型直接量可以具有小数(decimal)点,它们采用的是实数的传统语法。

Floating-Point literals may also be represented using exponential notation: a real number followed by the letter e(or E), followed by an optional plus or minus sign, followed by an integer exponent.
此外,还可以使用指数记数法表示浮点型直接量,即实数后跟随字母e或E,后面加上正负号,其后再加一个整型指数。

This notation represents the real number multiplied by 10 to the power of the exponent.
这种记数法表示的数值等于前面的实数乘以(multiplied by)10的指数(exponent)次幂(power)。

Working with Numbers 数字的使用

JavaScript programs work with numbers using the arithmetic operators that the language provides.
JavaScript是使用语言自身提供的算术(arithmetic)运算符来进行数字运算的。

In addition to these basic arithmetic operations (+ – * /) , JavaScript supports more complex mathematical operations through a large number of mathematical functions that are a core part of the language.
除了基本的(加减乘除)算术运算(mathematical operations)外,JavaScript还采用了大量的算术函数,来支持更为复杂的算术运算,这些函数是语言核心(core)的一部分。

Numeric Conversionsnju:ˈmerik kənˈvə:ʃən数值转换

JavaScript can format numbers as strings and parse strings into numbers.
JavaScript可以把数字格式化为字符串(strings)或者把字符串解析(parse)为数值。

Special Numeric Values 特殊的数值

When a floating-point value becomes larger than the largest representable finite number, the result is a special infinity value, which JavaScript prints as Infinity.
当一个浮点值大于所能表示的最大值时,其结果是一个特殊的无穷大值,JavaScript将它输出为Infinity

Similarly, when a negative value becomes lower than the last representable negative number, the result is negative infinity, printed as -Infinity.
同样的,当一个负值比所能表示的最小的负值还小时,结果就是负无穷大,输出为-Infinity

When a mathematical operation (such as division of zero by zero) yields an undefined result or an error , the result is the special not-a-number value, printed as NaN.
当一个算术运算(比如0除以0)产生了未定义的结果或错误时,结果是一个非数字的特殊值,输出为 NaN

Referenceˈrefrəns参考

《JavaScript权威指南》