Eric,

For example,

package main

import (
    "fmt"
    "runtime"
)

func main() {
    // Correctly prints "+0 00\n" as +00 00
    fmt.Printf("%s: %+03d %02d\n", runtime.Version(), 0, 0)
}

Output:

go1.10.3: +00 00

Playground: https://play.golang.org/p/Pt2-YJfQvEo

Widths three and two.

Peter

On Tuesday, August 28, 2018 at 4:49:02 PM UTC-4, peterGo wrote:
>
> Eric,
>
> "Width is specified by an optional decimal number immediately preceding 
> the verb. If absent, the width is whatever is necessary to represent the 
> value. "
>
> https://golang.org/pkg/fmt/
>
> Width is two.
>
> Peter
>
> On Tuesday, August 28, 2018 at 12:09:26 PM UTC-4, Eric Raymond wrote:
>>
>> Under Go 1.10.1, feeding an 0 value to a %+02d specifier sometimes 
>> yields  "+0", not "+00". The attached tiny Go program may reproduce this 
>> behavior.  I say "may" because I first observed it in a series of unit 
>> tests of date format conversions - in different format strings %+02d 
>> expanded differently.  I haven't found a pattern to this, or I'd report it. 
>> On my system this program, at least, has repeatable behavior.
>>
>> If this behavior were consistent, I'm not sure it would be a bug. It's 
>> possible that the sign is supposed to be counted as part of the number 
>> width; if so, it's an interesting question whether this is the right thing 
>> when explicit sign is forced by +.  The documentation is unclear.
>>
>> The apparent inconsistency worries me.  There may be some state in the 
>> form,at-interpretation code that is not always tracked correctly.
>>
>> In accordance with the Contribution Guidelines, I'm tossing  the question 
>> out here for a sanity check before throwing it on the bugtracker.  Have 
>> there been any similar reports?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to