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

Closed
vvekic opened this issue Jan 24, 2017 · 5 comments
Closed

Comments

@vvekic
Copy link

vvekic commented Jan 24, 2017

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

1.7.3

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

darwin amd64

What did you do?

https://play.golang.org/p/LEVTU7r4wX

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
@ALTree
Copy link
Member

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.

@ianlancetaylor
Copy link
Contributor

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

CC @robpike @martisch

@rsc
Copy link
Contributor

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.

@griesemer
Copy link
Contributor

It may suffice to replace

%g	%e for large exponents, %f otherwise

with

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

@gopherbot
Copy link

CL https://golang.org/cl/37313 mentions this issue.

@golang golang locked and limited conversation to collaborators Feb 21, 2018
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants