Skip to content

strconv: FormatFloat handles prec differently from the doc with fmt='g' #25082

@musiphil

Description

@musiphil

What version of Go are you using (go version)?

go version go1.10.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

What did you do?

fmt.Println(strconv.FormatFloat(1.5, 'g', 6, 64))
https://play.golang.org/p/WRHc89mjuSG

What did you expect to see?

1.50000

https://golang.org/pkg/strconv/#FormatFloat says:

The precision prec controls the number of digits […]. For 'g' and 'G' it is the total number of digits.

I gave prec=6, so the total number of digits should be 6.

What did you see instead?

1.5

The total number of digits is 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions