Here it is... try to figure out the why part before reading the explanation later...
type TT float64
func (t TT) String() string {
return fmt.Sprintf("%v", t)
}
func main() {
var t TT = 12.34
t.String()
}
Explanation:
Print methods that do not use any format specifiers internally call String() method on respective data. Example: Println or Printf with %v.
Notice that
%vtoo behaves similarly..
Top comments (0)