From d3c6fc0219a03ba68c906c6f830286f9ed0c2625 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sat, 7 Feb 2026 23:29:47 +0100 Subject: [PATCH] fix(fstring): display absolute value of int after sign --- examples/basic/23_format_spec.peb | 10 ++++++++++ src/core/format_spec/string_formatter.py | 1 + 2 files changed, 11 insertions(+) diff --git a/examples/basic/23_format_spec.peb b/examples/basic/23_format_spec.peb index 765fdd6..d260344 100644 --- a/examples/basic/23_format_spec.peb +++ b/examples/basic/23_format_spec.peb @@ -12,6 +12,12 @@ print(f"{c:,._}") print(f"{c:_.,}") // Sign +let d1 = 14 +let d2 = -26 +print(f"{d1} {d2}") +print(f"{d1:+} {d2:+}") +print(f"{d1:-} {d2:-}") +print(f"{d1: } {d2: }") // Percentage let pts = 19 @@ -19,5 +25,9 @@ let total = 22 print(f"Correct answers: {pts/total:.2%}") // Precision +print(f"{c:8}") +print(f"{c:8.2}") +print(f"{c:.2}") +print(f"{c:.8}") // Complex \ No newline at end of file diff --git a/src/core/format_spec/string_formatter.py b/src/core/format_spec/string_formatter.py index b6b7ea8..5d301fd 100644 --- a/src/core/format_spec/string_formatter.py +++ b/src/core/format_spec/string_formatter.py @@ -87,6 +87,7 @@ class StringFormatter: raise PebbleRuntimeError(spec.number.decimal.dot, "Incompatible decimal options with int type.") sign: str = self.make_sign(value, spec) + value = abs(value) string: str = self.format_int_part(value, fmt_type, spec.number.integral.grouping) return sign + string