From e1f9499ecfff24fac827749719e5e53c0e5acaeb Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Sat, 28 Jan 2023 19:56:34 -0800 Subject: [PATCH] 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 Reviewed-by: Ian Lance Taylor Reviewed-by: Michael Knyszek Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Auto-Submit: Ian Lance Taylor --- src/strconv/example_test.go | 5 +++++ 1 file changed, 5 insertions(+) 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() { -- 2.50.0