From 5ad5b7a551b30d27d7af00e3e981014f4acd8bd4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20Geisend=C3=B6rfer?= Date: Thu, 12 Dec 2013 06:40:16 -0800 Subject: [PATCH] fmt: Fix signed zero-padding for positive floats Space padding still has the same issue, I will send a separate patch for that if this one gets accepted. Fixes #6856. R=golang-dev, r CC=golang-dev https://golang.org/cl/35660043 --- src/pkg/fmt/fmt_test.go | 2 ++ src/pkg/fmt/format.go | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go index bf50675f54..444297d926 100644 --- a/src/pkg/fmt/fmt_test.go +++ b/src/pkg/fmt/fmt_test.go @@ -220,6 +220,8 @@ var fmtTests = []struct { {"%+.3e", 0.0, "+0.000e+00"}, {"%+.3e", 1.0, "+1.000e+00"}, {"%+.3f", -1.0, "-1.000"}, + {"%+07.2f", 1.0, "+001.00"}, + {"%+07.2f", -1.0, "-001.00"}, {"% .3E", -1.0, "-1.000E+00"}, {"% .3e", 1.0, " 1.000e+00"}, {"%+.3g", 0.0, "+0"}, diff --git a/src/pkg/fmt/format.go b/src/pkg/fmt/format.go index 2e2b0716ed..a54f12ee9f 100644 --- a/src/pkg/fmt/format.go +++ b/src/pkg/fmt/format.go @@ -372,7 +372,10 @@ func (f *fmt) formatFloat(v float64, verb byte, prec, n int) { default: // There's no sign, but we might need one. if f.plus { - slice[0] = '+' + f.buf.WriteByte('+') + f.wid-- + f.pad(slice[1:]) + return } else if f.space { // space is already there } else { -- 2.48.1