Skip to main content

6. Numbers (数字)

The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed.

数字的表示方式与大多数编程语言中使用的类似。数字使用十进制数字以10为基数表示。它包含一个整数部分,可以带有可选的负号前缀,后面可以跟分数部分和/或指数部分。不允许前导零。

A fraction part is a decimal point followed by one or more digits.

分数部分是小数点后跟一个或多个数字。

An exponent part begins with the letter E in upper or lower case, which may be followed by a plus or minus sign. The E and optional sign are followed by one or more digits.

指数部分以大写或小写字母E开头,后面可以跟加号或减号。E和可选符号后跟一个或多个数字。

Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.

不允许使用下面语法中无法表示的数值(如Infinity和NaN)。

number = [ minus ] int [ frac ] [ exp ]

decimal-point = %x2E ; .

digit1-9 = %x31-39 ; 1-9

e = %x65 / %x45 ; e E

exp = e [ minus / plus ] 1*DIGIT

frac = decimal-point 1*DIGIT

int = zero / ( digit1-9 *DIGIT )

minus = %x2D ; -

plus = %x2B ; +

zero = %x30 ; 0

This specification allows implementations to set limits on the range and precision of numbers accepted. Since software that implements IEEE 754-2008 binary64 (double precision) numbers [IEEE754] is generally available and widely used, good interoperability can be achieved by implementations that expect no more precision or range than these provide, in the sense that implementations will approximate JSON numbers within the expected precision. A JSON number such as 1E400 or 3.141592653589793238462643383279 may indicate potential interoperability problems, since it suggests that the software that created it expects receiving software to have greater capabilities for numeric magnitude and precision than is widely available.

本规范允许实现对接受的数字的范围和精度设置限制。由于实现IEEE 754-2008 binary64(双精度)数字[IEEE754]的软件通常可用且被广泛使用,通过期望精度或范围不超过这些提供的实现可以获得良好的互操作性,因为实现将在预期精度内近似JSON数字。像1E400或3.141592653589793238462643383279这样的JSON数字可能表明潜在的互操作性问题,因为它表明创建它的软件期望接收软件具有比广泛可用的更大的数值大小和精度能力。

Note that when such software is used, numbers that are integers and are in the range [-(253)+1, (253)-1] are interoperable in the sense that implementations will agree exactly on their numeric values.

注意,当使用此类软件时,范围在[-(253)+1, (253)-1]内的整数是互操作的,因为实现将完全一致地确定其数值。