mirror of
https://github.com/golang/go
synced 2024-11-12 06:30:21 -07:00
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
This commit is contained in:
parent
1d08fc44e9
commit
5ad5b7a551
@ -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"},
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user