Skip to content

micropython incorrectly omits grouping character in leading zeros #18082

@jepler

Description

@jepler

Port, board and/or hardware

unix port, coverage build

MicroPython version

MicroPython v1.26.0-preview.456.gec07a71df2.dirty on 2025-09-15; linux [GCC 14.2.0] version
(based on v1.25.0-451-gab620f4084)

Reproduction

Run the following code in MicroPython or CPython (3.11, 3.13 tested):

>>> "{:017_d}".format(3)

Expected behaviour

Python 3.11 outputs:

Python 3.11.10 (main, Oct  2 2024, 16:32:22) [Clang 18.1.8 ] on linux
>>> "{:017_d}".format(3)
'0_000_000_000_003'

Observed behaviour

MicroPython doesn't correctly add separator characters in the leading zero part:

MicroPython v1.26.0-preview.456.gec07a71df2.dirty on 2025-09-15; linux [GCC 14.2.0] version
>>> "{:017_d}".format(3)
'00000000000000003'

Additional Information

This also affects the _ grouping e.g., of numbers printed in hex

Code of Conduct

Yes, I agree

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