-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Description
What version of Go are you using (go version)?
go playground and go 1.8.3 linux/amd64
Does this issue reproduce with the latest release?
checked only for go playground and go 1.8.3 linux/amd64
What operating system and processor architecture are you using (go env)?
ubuntu linux x64
What did you do?
Playground:
https://play.golang.org/p/VNajWTsFQRd
Code:
package main
import (
"fmt"
"math/big"
)
type Val struct {
a int
b float64
}
func (v Val) String() string {
return fmt.Sprintf("Val{%d,%v}", v.a, v.b)
}
func main() {
// user struct
vl := Val{12, 45}
fmt.Printf("User struct => %s\n", vl)
// big float
f := big.NewFloat(23)
fmt.Printf("Big Float 1 => %s\n", f)
fmt.Printf("Big Float 2 => %s\n", (*f))
fmt.Printf("Big Float 3 => %s\n", f.String())
fmt.Printf("Big Float 4 => %s\n", (*f).String())
fmt.Println("Big Float 5 => ", f)
}Expected behavior:
struct big.Floatimplemented interfaceStringerfrom packagefmt.- In according to doc package
fmt:
- If an operand implements method String() string, that method will be invoked to convert the object to a string, which will then be formatted as required by the verb (if any).
What did you expect to see?
User struct => Val{12,45}
Big Float 1 => 23
Big Float 2 => 23
Big Float 3 => 23
Big Float 4 => 23
Big Float 5 => 23
What did you see instead?
Result from golang platground:
User struct => Val{12,45}
Big Float 1 => %!s(*big.Float=23)
Big Float 2 => {%!s(uint32=53) %!s(big.RoundingMode=0) %!s(big.Accuracy=0) %!s(big.form=1) %!s(bool=false) [%!s(big.Word=0) %!s(big.Word=3087007744)] %!s(int32=5)}
Big Float 3 => 23
Big Float 4 => 23
Big Float 5 => 23