]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: Fix signed zero-padding for positive floats
authorFelix Geisendörfer <haimuiba@gmail.com>
Thu, 12 Dec 2013 14:40:16 +0000 (06:40 -0800)
committerRob Pike <r@golang.org>
Thu, 12 Dec 2013 14:40:16 +0000 (06:40 -0800)
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
src/pkg/fmt/format.go

index bf50675f54359ff12d05179d15c8e15077aba98f..444297d9265b02bf69a4455cee175fddea0673f8 100644 (file)
@@ -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"},
index 2e2b0716edc822e4486415580c673da6280311d2..a54f12ee9f9f08fd80a1c0c704960779f5834795 100644 (file)
@@ -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 {