aboutsummaryrefslogtreecommitdiff
path: root/src/strconv
diff options
context:
space:
mode:
authorKevin Burke <kevin@burke.dev>2023-01-28 19:56:34 -0800
committerGopher Robot <gobot@golang.org>2023-01-31 16:01:01 +0000
commite1f9499ecfff24fac827749719e5e53c0e5acaeb (patch)
tree121294226b866ebab538bad8b73557f1f49e499f /src/strconv
parentf298b90bc56540e4313b7b7d3ecf08b1390b644f (diff)
downloadgo-e1f9499ecfff24fac827749719e5e53c0e5acaeb.tar.xz
strconv: show what fmt package uses for float printing
The strconv docs are not very helpful for people who just want to pick a reasonable default, for example the one used by the fmt package to show floats. Add an example illustrating what the fmt package uses. Change-Id: Iefefa70dfd4d4bfa9962a20654ee23662818ef38 Reviewed-on: https://go-review.googlesource.com/c/go/+/463980 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/strconv')
-rw-r--r--src/strconv/example_test.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/strconv/example_test.go b/src/strconv/example_test.go
index 3b4cedbfd8..b02392de6a 100644
--- a/src/strconv/example_test.go
+++ b/src/strconv/example_test.go
@@ -134,9 +134,14 @@ func ExampleFormatFloat() {
s64 := strconv.FormatFloat(v, 'E', -1, 64)
fmt.Printf("%T, %v\n", s64, s64)
+ // fmt.Println uses these arguments to print floats
+ fmt64 := strconv.FormatFloat(v, 'g', -1, 64)
+ fmt.Printf("%T, %v\n", fmt64, fmt64)
+
// Output:
// string, 3.1415927E+00
// string, 3.1415926535E+00
+ // string, 3.1415926535
}
func ExampleFormatInt() {