]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: show what fmt package uses for float printing
authorKevin Burke <kevin@burke.dev>
Sun, 29 Jan 2023 03:56:34 +0000 (19:56 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 31 Jan 2023 16:01:01 +0000 (16:01 +0000)
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>

src/strconv/example_test.go

index 3b4cedbfd82cb2fe777ac1bfba82ded2ec90d0d7..b02392de6a882030a203b5a87af4275576c44fb8 100644 (file)
@@ -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() {