Skip to content
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

fmt: wrong output for format %g #458

Closed
gopherbot opened this issue Dec 24, 2009 · 2 comments
Closed

fmt: wrong output for format %g #458

gopherbot opened this issue Dec 24, 2009 · 2 comments
Assignees

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 24, 2009

by trukenmueller:

package main
import (
        "fmt"
)
func main() {
        var x float64
        x = 1.0/9.0
        fmt.Printf("%g %f\n",x,x)
}


What is the expected output?
0.111111 0.111111

%g should produce a short form (at least not longer than %f)

What do you see instead?
0.1111111111111111 0.111111

What is your $GOOS?  $GOARCH? linux 386


Which revision are you using?  (hg identify)
84e097972fa7 tip
@gopherbot
Copy link
Author

@gopherbot gopherbot commented Dec 28, 2009

Comment 1 by trukenmueller:

fix is submitted for review: http://golang.org/cl/183070
@rsc
Copy link
Contributor

@rsc rsc commented Dec 28, 2009

Comment 2:

%g in Go is different from %g in C.
%g in Go means print as many digits as are necessary
for strconv.Atof64 or strconv.Atof32 (depending on
the type being printed) to reconstruct exactly the
same value.
To limit the number of digits (and give up this property)
use a size modifier as in %6g.

Owner changed to r...@golang.org.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.