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