Skip to content

Commit

Permalink
Merge pull request godotengine#42480 from ssw99/sprintf-function-bug-fix
Browse files Browse the repository at this point in the history
Fix extra padding for numbers with signs
  • Loading branch information
akien-mga authored Oct 2, 2020
2 parents 6189ff8 + 9f2cdfe commit a1c2722
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4484,11 +4484,12 @@ String String::sprintf(const Array &values, bool *error) const {
int number_len = str.length();

// Padding.
int pad_chars_count = (value < 0 || show_sign) ? min_chars - 1 : min_chars;
String pad_char = pad_with_zeroes ? String("0") : String(" ");
if (left_justified) {
str = str.rpad(min_chars, pad_char);
str = str.rpad(pad_chars_count, pad_char);
} else {
str = str.lpad(min_chars, pad_char);
str = str.lpad(pad_chars_count, pad_char);
}

// Sign.
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/doc_classes/@GDScript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@
Returns the integer modulus of [code]a/b[/code] that wraps equally in positive and negative.
[codeblock]
for i in range(-3, 4):
print("%2.0f %2.0f %2.0f" % [i, i % 3, posmod(i, 3)])
print("%2d %2d %2d" % [i, i % 3, posmod(i, 3)])
[/codeblock]
Produces:
[codeblock]
Expand Down

0 comments on commit a1c2722

Please sign in to comment.