bpo-39096: Improve description of 'e', 'f' and 'g' presentation types… · python/cpython@c642374 (original) (raw)

`@@ -384,10 +384,10 @@ following:

`

384

384

``

385

385

``` The '#' option causes the "alternate form" to be used for the


`386`

`386`

`conversion. The alternate form is defined differently for different

`

`387`

``

`-

types. This option is only valid for integer, float, complex and

`

`388`

``

`-

Decimal types. For integers, when binary, octal, or hexadecimal output

`

``

`387`

`+

types. This option is only valid for integer, float and complex

`

``

`388`

`+

types. For integers, when binary, octal, or hexadecimal output

`

`389`

`389`

``` is used, this option adds the prefix respective ``'0b'``, ``'0o'``, or

390

``


``'0x'`` to the output value. For floats, complex and Decimal the

``

390


``'0x'`` to the output value. For float and complex the

391

391

`alternate form causes the result of the conversion to always contain a

`

392

392

`decimal-point character, even if no digits follow it. Normally, a

`

393

393

`decimal-point character appears in the result of these conversions

`

`@@ -476,20 +476,36 @@ with the floating point presentation types listed below (except

`

476

476

``` 'n' and None). When doing so, :func:float is used to convert the


`477`

`477`

`integer to a floating point number before formatting.

`

`478`

`478`

``

`479`

``

`-

The available presentation types for floating point and decimal values are:

`

``

`479`

`` +

The available presentation types for :class:`float` and

``

``

`480`

`` +

:class:`~decimal.Decimal` values are:

``

`480`

`481`

``

`481`

`482`

`+---------+----------------------------------------------------------+

`

`482`

`483`

` | Type | Meaning |

`

`483`

`484`

`+=========+==========================================================+

`

`484`

``

``` -

| ``'e'`` | Exponent notation. Prints the number in scientific |

485

``

`-

| | notation using the letter 'e' to indicate the exponent. |

`

486

``


 | | The default precision is ``6``. |

``

485


 | ``'e'`` | Scientific notation. For a given precision ``p``, |

``

486

`+

| | formats the number in scientific notation with the |

`

``

487

`+

| | letter 'e' separating the coefficient from the exponent. |

`

``

488


 | | The coefficient has one digit before and ``p`` digits |

``

489


 | | after the decimal point, for a total of ``p + 1`` |

``

490

`+

| | significant digits. With no precision given, uses a |

`

``

491


 | | precision of ``6`` digits after the decimal point for |

``

492

`` +

| | :class:float, and shows all coefficient digits |

``

``

493

`` +

| | for :class:~decimal.Decimal. If no digits follow the |

``

``

494

`+

| | decimal point, the decimal point is also removed unless |

`

``

495


 | | the ``#`` option is used. |

487

496

`+---------+----------------------------------------------------------+

`

488

``


 | ``'E'`` | Exponent notation. Same as ``'e'`` except it uses an |

489

``

`-

| | upper case 'E' as the separator character. |

`

``

497


 | ``'E'`` | Scientific notation. Same as ``'e'`` except it uses |

``

498

`+

| | an upper case 'E' as the separator character. |

`

490

499

`+---------+----------------------------------------------------------+

`

491

``


 | ``'f'`` | Fixed-point notation. Displays the number as a |

492

``


 | | fixed-point number. The default precision is ``6``. |

``

500


 | ``'f'`` | Fixed-point notation. For a given precision ``p``, |

``

501

`+

| | formats the number as a decimal number with exactly |

`

``

502


 | | ``p`` digits following the decimal point. With no |

``

503


 | | precision given, uses a precision of ``6`` digits after |

``

504

`` +

| | the decimal point for :class:float, and uses a |

``

``

505

`+

| | precision large enough to show all coefficient digits |

`

``

506

`` +

| | for :class:~decimal.Decimal. If no digits follow the |

``

``

507

`+

| | decimal point, the decimal point is also removed unless |

`

``

508


 | | the ``#`` option is used. |

493

509

`+---------+----------------------------------------------------------+

`

494

510

``` | 'F' | Fixed-point notation. Same as 'f', but converts |


`495`

`511`

```  | | ``nan`` to ``NAN`` and ``inf`` to ``INF``. |

`@@ -518,7 +534,10 @@ The available presentation types for floating point and decimal values are:

`

518

534

` | | the precision. |

`

519

535

` | | |

`

520

536

``` | | A precision of 0 is treated as equivalent to a |


`521`

``

``` -

| | precision of ``1``. The default precision is ``6``. |

``

537


 | | precision of ``1``. With no precision given, uses a |

``

538


 | | precision of ``6`` significant digits for |

``

539

`` +

| | :class:float, and shows all coefficient digits |

``

``

540

`` +

| | for :class:~decimal.Decimal. |

``

522

541

`+---------+----------------------------------------------------------+

`

523

542

``` | 'G' | General format. Same as 'g' except switches to |


`524`

`543`

```  | | ``'E'`` if the number gets too large. The |