Skip to content

BUG: format_float_positional() intermittently drops trailing zeros #21631

Open
@hhoppe

Description

@hhoppe

Describe the issue:

I am using np.format_float_positional() to output exactly 3 digits of precision.
See the code example below.
The output is:

0.0000314 0.000314 0.00314 0.0314 0.314 3.14 31.4 314. 3140. 31400.
0.0000310 0.00031 0.00310 0.0310 0.310 3.10 31.0 310. 3100. 31000.
0.0000250 0.000250 0.00250 0.0250 0.25 2.50 25.0 250. 2500. 25000.

In the second line, 0.00031 should be 0.000310.
And in the third line, 0.25 should be 0.250.

Reproduce the code example:

import numpy as np

for base_value in [np.pi, 3.1, 2.5]:
  print(' '.join(np.format_float_positional(value, fractional=False,
                                            precision=3, unique=False)
                 for value in base_value * 10.0**np.arange(-5, 5)))

Error message:

No response

NumPy/Python version information:

1.21.6 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions