{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/15178","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/15178/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/15178/comments","events_url":"https://api.github.com/repos/golang/go/issues/15178/events","html_url":"https://github.com/golang/go/issues/15178","id":146665623,"number":15178,"title":"Documentation unclear regarding %g precision formatting","user":{"login":"akiross","id":884092,"avatar_url":"https://avatars.githubusercontent.com/u/884092?v=3","gravatar_id":"","url":"https://api.github.com/users/akiross","html_url":"https://github.com/akiross","followers_url":"https://api.github.com/users/akiross/followers","following_url":"https://api.github.com/users/akiross/following{/other_user}","gists_url":"https://api.github.com/users/akiross/gists{/gist_id}","starred_url":"https://api.github.com/users/akiross/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akiross/subscriptions","organizations_url":"https://api.github.com/users/akiross/orgs","repos_url":"https://api.github.com/users/akiross/repos","events_url":"https://api.github.com/users/akiross/events{/privacy}","received_events_url":"https://api.github.com/users/akiross/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-07T15:49:31Z","updated_at":"2016-04-07T15:50:35Z","closed_at":null,"body":"Current go 1.5 documentation is not clear regarding the %g formatting. In particular, it states\r\n\r\n> For floating-point values, width sets the minimum width of the field and precision sets the number of places after the decimal, if appropriate, except that for %g/%G it sets the total number of digits. For example, given 123.45 the format %6.2f prints 123.45 while %.4g prints 123.5. The default precision for %e and %f is 6; for %g it is the smallest number of digits necessary to identify the value uniquely. \r\n\r\nThis seems to imply that width for %g/%G is the total number of digits that will be outputted, while it is the number of significant digits, therefore leading zeroes does not contribute to the count. For example, formatting 0.001234 with %.3g will be printed without changes, 0.001234, while from the docs it seems that only 0.001 should be printed.\r\n\r\nI propose to change the documentation and change the following:\r\n\r\n> except that for %g/%G it sets the total number of digits. For example, given 123.45 the format %6.2f prints 123.45 while %.4g prints 123.5.\r\n\r\nwith the following (bold used to mark the changes)\r\n\r\n> except that for %g/%G it sets the total number of **significant** digits. For example, given 123.45 the format %6.2f prints 123.45 while %.4g prints 123.5**, and 0.00123 is printed as 0.001 by %.3f, but printed as 0.00123 by %.3g**.\r\n\r\nOr with a better statement and/or example if the one I provided are not accurate enough."},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/206965134","html_url":"https://github.com/golang/go/issues/15178#issuecomment-206965134","issue_url":"https://api.github.com/repos/golang/go/issues/15178","id":206965134,"user":{"login":"akiross","id":884092,"avatar_url":"https://avatars.githubusercontent.com/u/884092?v=3","gravatar_id":"","url":"https://api.github.com/users/akiross","html_url":"https://github.com/akiross","followers_url":"https://api.github.com/users/akiross/followers","following_url":"https://api.github.com/users/akiross/following{/other_user}","gists_url":"https://api.github.com/users/akiross/gists{/gist_id}","starred_url":"https://api.github.com/users/akiross/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akiross/subscriptions","organizations_url":"https://api.github.com/users/akiross/orgs","repos_url":"https://api.github.com/users/akiross/repos","events_url":"https://api.github.com/users/akiross/events{/privacy}","received_events_url":"https://api.github.com/users/akiross/received_events","type":"User","site_admin":false},"created_at":"2016-04-07T15:50:35Z","updated_at":"2016-04-07T15:50:35Z","body":"See this for a discussion on the topic http://stackoverflow.com/questions/36464068/fmt-printf-with-width-and-precision-fields-in-g-behaves-unexpectedly"}}