Enumerating JSON numeric literals

JSON numeric literals conform to the regular expression:

-?(0|[1-9][0-9]*)(\.[0-9]+)?([Ee][+\-]?[0-9]+)?

In other words there is an optional leading negative sign, one or more digits (leading zeroes are not allowed), an optional decimal part and an optional exponent. Note that it is not permissible to omit the leading digit on a decimal e.g. '.123', to omit trailing digits after a decimal e.g. '456.' or use a leading plus sign e.g. '+789'.

The easiest way to count these is by separately considering formats with and without decimals, formats with and without exponents and, at the highest level, formats with and without the leading negative sign.

Throughout the following, N is string length. This is fully unambiguous because all the characters in use are pure ASCII.

Non-negative numeric literals

Integers

These have neither a decimal point nor an exponent.

N Count Examples
0 0 none
1 10 '0' to '9'
2 90 '10' to '99'
3 900 '100' to '999'
4 9,000 '1000' to '9999'
5 90,000 '10000' to '99999'
≥ 2 9 × 10N - 1 ...

Decimals

These have a decimal part but no exponent. Bear with me on how these are enumerated, it makes the calculation more logical...

N Count Examples
0 0 none
1 0 none
2 0 none
3 100 '0.0' to '0.9' (10)
'1.0' to '9.9' (90)
4 1,900 '0.00' to '0.99' (100)
'1.00' to '9.99' (900)
'10.0' to '99.9' (900)
5 28,000 '0.000' to '0.999' (1,000)
'1.000' to '9.999' (9,000)
'10.00' to '99.99' (9,000)
'100.0' to '999.9' (9,000)
6 370,000 '0.0000' to '0.9999' (10,000)
'1.0000' to '9.9999' (90,000)
'10.000' to '99.999' (90,000)
'100.00' to '999.99' (90,000)
'1000.0' to '9999.9' (90,000)
≥ 3 (1 + 9(N - 2)) × 10N - 2 =
(9N - 17) × 10N - 2
...

Unsigned exponents

These have an unsigned exponent but no decimal part. Results are multiplied by 2 because there are two possible unsigned exponent symbols, 'E' and 'e'.

N Count Examples
0 0 none
1 0 none
2 0 none
3 200

'0E0' to '0E9' (10)
'1E0' to '9E9' (90)

'0e0' to '0e9' (10)
'1e0' to '9e9' (90)

4 3,800

'0E00' to '0E99' (100)
'1E00' to '9E99' (900)
'10E0' to '99E9' (900)

'0e00' to '0E99' (100)
'1e00' to '9E99' (900)
'10e0' to '99e9' (900)

5 56,000

'0E000' to '0E999' (1,000)
'1E000' to '9E999' (9,000)
'10E00' to '99E99' (9,000)
'100E0' to '999E9' (9,000)

'0e000' to '0e999' (1,000)
'1e000' to '9e999' (9,000)
'10e00' to '99e99' (9,000)
'100e0' to '999e9' (9,000)

6 740,000

'0E0000' to '0E9999' (10,000)
'1E0000' to '9E9999' (90,000)
'10E000' to '99E999' (90,000)
'100E00' to '999E99' (90,000)
'1000E0' to '9999E9' (90,000)

'0e0000' to '0e9999' (10,000)
'1e0000' to '9e9999' (90,000)
'10e000' to '99e999' (90,000)
'100e00' to '999e99' (90,000)
'1000e0' to '9999e9' (90,000)

≥ 3 (1 + 9(N - 2)) × 10N - 2 × 2 =
(18N - 34) × 10N - 2
...

Signed exponents

These have a signed exponent but no decimal part. Results are multiplied by 4 because there are four possible signed exponent symbols, 'E+', 'E-', 'e+' and 'e-'.

N Count Examples
0 0 none
1 0 none
2 0 none
3 0 none
4 400

'0E+0' to '0E+9' (10)
'1E+0' to '9E+9' (90)

'0E-0' to '0E-9' (10)
'1E-0' to '9E-9' (90)

'0e+0' to '0e+9' (10)
'1e+0' to '9e+9' (90)

'0e-0' to '0e-9' (10)
'1e-0' to '9e-9' (90)

5 7,600

'0E+00' to '0E+99' (100)
'1E+00' to '9E+99' (900)
'10E+0' to '99E+9' (900)

'0E-00' to '0E-99' (100)
'1E-00' to '9E-99' (900)
'10E-0' to '99E-9' (900)

'0e+00' to '0e+99' (100)
'1e+00' to '9e+99' (900)
'10e+0' to '99e+9' (900)

'0e-00' to '0e-99' (100)
'1e-00' to '9e-99' (900)
'10e-0' to '99e-9' (900)

6 112,000

'0E+000' to '0E+999' (1,000)
'1E+000' to '9E+999' (9,000)
'10E+00' to '99E+99' (9,000)
'100E+0' to '999E+9' (9,000)

'0E-000' to '0E-999' (1,000)
'1E-000' to '9E-999' (9,000)
'10E-00' to '99E-99' (9,000)
'100E-0' to '999E-9' (9,000)

'0e+000' to '0e+999' (1,000)
'1e+000' to '9e+999' (9,000)
'10e+00' to '99e+99' (9,000)
'100e+0' to '999e+9' (9,000)

'0e-000' to '0e-999' (1,000)
'1e-000' to '9e-999' (9,000)
'10e-00' to '99e-99' (9,000)
'100e-0' to '999e-9' (9,000)

7 1,480,000

'0E+0000' to '0E+9999' (10,000)
'1E+0000' to '9E+9999' (90,000)
'10E+000' to '99E+999' (90,000)
'100E+00' to '999E+99' (90,000)
'1000E+0' to '9999E+9' (90,000)

'0E-0000' to '0E-9999' (10,000)
'1E-0000' to '9E-9999' (90,000)
'10E-000' to '99E-999' (90,000)
'100E-00' to '999E-99' (90,000)
'1000E-0' to '9999E-9' (90,000)

'0e+0000' to '0e+9999' (10,000)
'1e+0000' to '9e+9999' (90,000)
'10e+000' to '99e+999' (90,000)
'100e+00' to '999e+99' (90,000)
'1000e+0' to '9999e+9' (90,000)

'0e-0000' to '0e-9999' (10,000)
'1e-0000' to '9e-9999' (90,000)
'10e-000' to '99e-999' (90,000)
'100e-00' to '999e-99' (90,000)
'1000e-0' to '9999e-9' (90,000)

≥ 4 (1 + 9(N - 3)) × 10N - 3 × 4 =
(36N - 104) × 10N - 3
...

Decimal unsigned exponents

These have a decimal part and an unsigned exponent. Results are multiplied by 2 because there are two possible unsigned exponent symbols, 'E' and 'e'. The calculation is more complicated because there are O(N2) combinations of locations for the decimal point and the exponent symbol.

N Count Examples
0 0 none
1 0 none
2 0 none
3 0 none
4 0 none
5 2,000

'0.0E0' to '0.9E9' (100)
'1.0E0' to '9.9E9' (900)

'0.0e0' to '0.9e9' (100)
'1.0e0' to '9.9e9' (900)

6 58,000

'0.0E00' to '0.9E99' (1,000)
'0.00E0' to '0.99E9' (1,000)
'1.0E00' to '9.9E99' (9,000)
'1.00E0' to '9.99E9' (9,000)
'10.0E0' to '99.9E9' (9,000)

'0.0e00' to '0.9e99' (1,000)
'0.00e0' to '0.99e9' (1,000)
'1.0e00' to '9.9e99' (9,000)
'1.00e0' to '9.99e9' (9,000)
'10.0e0' to '99.9e9' (9,000)

7 1,140,000

'0.0E000' to '0.9E999' (10,000)
'0.00E00' to '0.99E99' (10,000)
'0.000E0' to '0.999E9' (10,000)
'1.0E000' to '9.9E999' (90,000)
'1.00E00' to '9.99E99' (90,000)
'1.000E0' to '9.999E9' (90,000)
'10.0E00' to '99.9E99' (90,000)
'10.00E0' to '99.99E9' (90,000)
'100.0E0' to '999.9E9' (90,000)

'0.0e000' to '0.9e999' (10,000)
'0.00e00' to '0.99e99' (10,000)
'0.000e0' to '0.999e9' (10,000)
'1.0e000' to '9.9e999' (90,000)
'1.00e00' to '9.99e99' (90,000)
'1.000e0' to '9.999e9' (90,000)
'10.0e00' to '99.9e99' (90,000)
'10.00e0' to '99.99e9' (90,000)
'100.0e0' to '999.9e9' (90,000)

≥ 4 ((N - 4) + 9(N - 3)(N - 4)/2) × 10N - 3 × 2 =
(9N2 - 61N + 100) × 10N - 3
...

Decimal signed exponents

These have a decimal part and a signed exponent. Results are multiplied by 4 because there are four possible signed exponent symbols, 'E+', 'E-', 'e+' and 'e-'. The calculation is more complicated because there are O(N2) combinations of locations for the decimal point and the exponent symbol.

N Count Examples
0 0 none
1 0 none
2 0 none
3 0 none
4 0 none
5 0 none
6 4,000

'0.0E+0' to '0.9E+9' (100)
'1.0E+0' to '9.9E+9' (900)

'0.0E-0' to '0.9E-9' (100)
'1.0E-0' to '9.9E-9' (900)

'0.0e+0' to '0.9e+9' (100)
'1.0e+0' to '9.9e+9' (900)

'0.0e-0' to '0.9e-9' (100)
'1.0e-0' to '9.9e-9' (900)

7 116,000

'0.0E+00' to '0.9E+99' (1,000)
'0.00E+0' to '0.99E+9' (1,000)
'1.0E+00' to '9.9E+99' (9,000)
'1.0E-00' to '9.9E-99' (9,000)
'1.00E+0' to '9.99E+9' (9,000)
'10.0E+0' to '99.9E+9' (9,000)

'0.0E-00' to '0.9E-99' (1,000)
'0.00E-0' to '0.99E-9' (1,000)
'1.00E-0' to '9.99E-9' (9,000)
'10.0E-0' to '99.9E-9' (9,000)

'0.0e+00' to '0.9e+99' (1,000)
'0.00e+0' to '0.99e+9' (1,000)
'1.0e+00' to '9.9e+99' (9,000)
'1.00e+0' to '9.99e+9' (9,000)
'10.0e+0' to '99.9e+9' (9,000)

'0.0e-00' to '0.9e-99' (1,000)
'0.00e-0' to '0.99e-9' (1,000)
'1.0e-00' to '9.9e-99' (9,000)
'1.00e-0' to '9.99e-9' (9,000)
'10.0e-0' to '99.9e-9' (9,000)

8 2,280,000

'0.0E+000' to '0.9E+999' (10,000)
'0.00E+00' to '0.99E+99' (10,000)
'0.000E+0' to '0.999E+9' (10,000)
'1.0E+000' to '9.9E+999' (90,000)
'1.00E+00' to '9.99E+99' (90,000)
'1.000E+0' to '9.999E+9' (90,000)
'10.0E+00' to '99.9E+99' (90,000)
'10.00E+0' to '99.99E+9' (90,000)
'100.0E+0' to '999.9E+9' (90,000)

'0.0E-000' to '0.9E-999' (10,000)
'0.00E-00' to '0.99E-99' (10,000)
'0.000E-0' to '0.999E-9' (10,000)
'1.0E-000' to '9.9E-999' (90,000)
'1.00E-00' to '9.99E-99' (90,000)
'1.000E-0' to '9.999E-9' (90,000)
'10.0E-00' to '99.9E-99' (90,000)
'10.00E-0' to '99.99E-9' (90,000)
'100.0E-0' to '999.9E-9' (90,000)

'0.0e+000' to '0.9e+999' (10,000)
'0.00e+00' to '0.99e+99' (10,000)
'0.000e+0' to '0.999e+9' (10,000)
'1.0e+000' to '9.9e+999' (90,000)
'1.00e+00' to '9.99e+99' (90,000)
'1.000e+0' to '9.999e+9' (90,000)
'10.0e+00' to '99.9e+99' (90,000)
'10.00e+0' to '99.99e+9' (90,000)
'100.0e+0' to '999.9e+9' (90,000)

'0.0e-000' to '0.9e-999' (10,000)
'0.00e-00' to '0.99e-99' (10,000)
'0.000e-0' to '0.999e-9' (10,000)
'1.0e-000' to '9.9e-999' (90,000)
'1.00e-00' to '9.99e-99' (90,000)
'1.000e-0' to '9.999e-9' (90,000)
'10.0e-00' to '99.9e-99' (90,000)
'10.00e-0' to '99.99e-9' (90,000)
'100.0e-0' to '999.9e-9' (90,000)

≥ 5 ((N - 5) + 9(N - 4)(N - 5)/2) × 10N - 4 × 4 =
(18N2 - 158N + 340) × 10N - 4
...

All non-negative numeric literals

This is simply the sum of the previous six tables.

N Count
0 0
1 10
2 90
3 1,200
4 15,100
5 183,600
6 2,184,000
7 25,536,000
8 294,480,000
≥ 5 (108N2 + 2292N + 4200) × 10N - 4

Negative numeric literals

That is, numeric literals with a negative sign, such as -123.456E+789.

The number of negative JSON numeric literals of length N is simply the number of non-negative numeric literals of length N - 1. If N is 0 the count is 0.

N Count
0 0
1 0
2 10
3 90
4 1,200
5 15,100
6 183,600
7 2,184,000
8 25,536,000
9 294,480,000
≥ 6 (108N2 + 2076N + 2016) × 10N - 5

All numeric literals

This is simply the sum of the previous two tables.

N Count
0 0
1 10
2 100
3 1,290
4 16,300
5 198,700
6 2,367,600
7 27,720,000
8 320,016,000
9 3,652,080,000
≥ 6 (1188N2 + 24996N + 44016) × 10N - 5

Example

There are 198,700 JSON numeric literals of length 5. These are:

  • 183,600 non-negative numeric literals:

    • 90,000 integers '10000' to '99999'
    • 10,000 decimals '0.000' to '9.999'
    • 9,000 decimals '10.00' to '99.99'
    • 9,000 decimals '100.0' to '999.9'
    • 10,000 unsigned exponents '0E000' to '9E999'
    • 10,000 unsigned exponents '0e000' to '9e999'
    • 9,000 unsigned exponents '10E00' to '99E99'
    • 9,000 unsigned exponents '10e00' to '99e99'
    • 9,000 unsigned exponents '100E0' to '999E9'
    • 9,000 unsigned exponents '100e0' to '999e9'
    • 1,000 signed exponents '0E+00' to '9E+99'
    • 1,000 signed exponents '0E-00' to '9E-99'
    • 1,000 signed exponents '0e+00' to '9e+99'
    • 1,000 signed exponents '0e-00' to '9e-99'
    • 900 signed exponents '10E+0' to '99E+9'
    • 900 signed exponents '10E-0' to '99E-9'
    • 900 signed exponents '10e+0' to '99e+9'
    • 900 signed exponents '10e-0' to '99e-9'
    • 1,000 decimal unsigned exponents '0.0E0' to '9.9E9'
    • 1,000 decimal unsigned exponents '0.0e0' to '9.9e9'
    • 0 decimal signed exponents
  • 15,100 negative numeric literals:

    • 9,000 integers '-1000' to '-9999'
    • 1,000 decimals -0.00' to '-9.99'
    • 900 decimals -10.0' to '-99.9'
    • 1,000 unsigned exponents -0E00' to '-9E99'
    • 1,000 unsigned exponents -0e00' to '-9e99'
    • 900 unsigned exponents -10E0' to '-99E9'
    • 900 unsigned exponents -10e0' to '-99e9'
    • 100 signed exponents '-0E+0' to '-9E+9'
    • 100 signed exponents '-0E-0' to '-9E-9'
    • 100 signed exponents '-0e+0' to '-9e-9'
    • 100 signed exponents '-0e-0' to '-0e-9'
    • 0 decimal signed exponents