-
Notifications
You must be signed in to change notification settings - Fork 18k
strconv: FormatFloat handles prec differently from the doc with fmt='g' #25082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Workaround: use I agree that the doc and the implementation are in contradiction, and either one or the other should be fixed. I'm not sure what is the basis for removing trailing zeros. The relevant piece of code seems to be here: https://golang.org/src/strconv/ftoa.go?s=5694:5737#L206 If the current implementation is preserved, I propose to fix like this:
Verbs
Yes, the doc for the |
Thanks, and I agree in general. I've always been mindful of communicating the correct number of significant digits. With Ideally, |
I don't think we should change the code, so marking this as a documentation fix. |
Hi! It seems that no one is working on this right now... have we agreed that this is just a doc change? May I do it? |
Change https://golang.org/cl/127135 mentions this issue: |
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:
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.
The text was updated successfully, but these errors were encountered: