From 6952124988e7b3d07969d833fb8790c28e2cb6fa Mon Sep 17 00:00:00 2001 From: finn Date: Thu, 1 Jun 2023 11:10:46 +0200 Subject: [PATCH] [fmt] fix zero-padding behaviour of numbers - when formatting a negative number with left zero-padding we expect the padding to be placed between the minus (-) sign and the number - currently the padding is placed before the sign --- core/fmt/fmt.odin | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index b82789813..192d36058 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -1142,6 +1142,11 @@ _pad :: proc(fi: ^Info, s: string) { if fi.minus { // right pad io.write_string(fi.writer, s, &fi.n) fmt_write_padding(fi, width) + } else if !fi.space && s != "" && s[0] == '-' { + // left pad accounting for zero pad of negative number + io.write_byte(fi.writer, '-', &fi.n) + fmt_write_padding(fi, width) + io.write_string(fi.writer, s[1:], &fi.n) } else { // left pad fmt_write_padding(fi, width) io.write_string(fi.writer, s, &fi.n)