Files
micropython/tests/basics/string_format_sep.py
Jeff Epler 5552fbe172 py/mpprint: Correctly format leading zeros with separators.
Correctly format integers when there are leading zeros with a grouping
character, such as "{:04,d}".format(0x100) -> "0,256".

The new padding patterns for commas-and-zeroes and underscores-and-zeroes
are smooshed together into the existing pad_zeroes to save space.

Only the two combinations of (decimal + commas) and (other bases +
underscores) are properly supported.

Also add a test for it.

Fixes issue #18082.

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
2025-10-06 15:07:34 +11:00

10 lines
246 B
Python

try:
"%d" % 1
except TypeError:
print("SKIP")
raise SystemExit
for v in (0, 0x10, 0x1000, -0x10, -0x1000):
for sz in range(1, 12): print(("{:0%d,d}" % sz).format(v))
for sz in range(1, 12): print(("{:0%d_x}" % sz).format(v))