mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
py/mpz: Skip separators when running out of digits to print.
This commit fixes the addition of a stray separator before the number when printing an MPZ-backed integer and the first group is three digits long. This fixes #8984. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
committed by
Damien George
parent
b0ba151102
commit
43b05afdf5
2
py/mpz.c
2
py/mpz.c
@@ -1717,7 +1717,7 @@ size_t mpz_as_str_inpl(const mpz_t *i, unsigned int base, const char *prefix, ch
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (comma && (s - last_comma) == 3) {
|
if (!done && comma && (s - last_comma) == 3) {
|
||||||
*s++ = comma;
|
*s++ = comma;
|
||||||
last_comma = s;
|
last_comma = s;
|
||||||
}
|
}
|
||||||
|
|||||||
15
tests/basics/string_format_intbig.py
Normal file
15
tests/basics/string_format_intbig.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# basic functionality test for {} format string using large integers
|
||||||
|
|
||||||
|
|
||||||
|
def test(fmt, *args):
|
||||||
|
print("{:8s}".format(fmt) + ">" + fmt.format(*args) + "<")
|
||||||
|
|
||||||
|
|
||||||
|
# Separator formatter
|
||||||
|
|
||||||
|
test("{:,}", 123_456_789_012_345_678_901_234_567)
|
||||||
|
test("{:,}", 23_456_789_012_345_678_901_234_567)
|
||||||
|
test("{:,}", 3_456_789_012_345_678_901_234_567)
|
||||||
|
test("{:,}", -123_456_789_012_345_678_901_234_567)
|
||||||
|
test("{:,}", -23_456_789_012_345_678_901_234_567)
|
||||||
|
test("{:,}", -3_456_789_012_345_678_901_234_567)
|
||||||
Reference in New Issue
Block a user