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: float64 formatting behaving differently than expected (and than documented) #18772

vvekic opened this issue Jan 24, 2017 · 5 comments


Copy link

@vvekic vvekic commented Jan 24, 2017

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


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

darwin amd64

What did you do?

What did you expect to see?

The %g-formatted (or %v) float64 number to be the same as either %f or %e, as per documentation.

What did you see instead?

The %g-formatted number was 24.849999999999998.

@ianlancetaylor ianlancetaylor changed the title float64 formatting behaving differently than expected (and than documented) fmt: float64 formatting behaving differently than expected (and than documented) Jan 24, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.9 milestone Jan 24, 2017
Copy link

@ALTree ALTree commented Jan 24, 2017

The default precision for %e and %f is 6; for %g it is the smallest number of digits necessary to identify the value uniquely.

Copy link

@ianlancetaylor ianlancetaylor commented Jan 24, 2017

Probably needs a doc tweak, as the short description of %g does suggest that it is either %e or %f.

CC @robpike @martisch

Copy link

@rsc rsc commented Jan 24, 2017

There's only so much we can say in a one-line summary. The full details of the precision are documented. I tend to think this is fine as is, unless someone can come up with a very short replacement for the current one-line summary.

Copy link

@griesemer griesemer commented Jan 24, 2017

It may suffice to replace

%g	%e for large exponents, %f otherwise


%g	%e for large exponents, %f otherwise (see below for default precision in this case)
Copy link

@gopherbot gopherbot commented Feb 21, 2017

CL mentions this issue.

@gopherbot gopherbot closed this in ea020ff Feb 21, 2017
@golang golang locked and limited conversation to collaborators Feb 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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