package main import ( "fmt" "reflect" ) func main() { var x float64 = 3.14 fmt.Println(reflect.ValueOf(x).String()) // prints "3.14" }
package main import ( "fmt" "reflect" ) type Person struct { Name string Age int } func main() { p := Person{Name: "John Doe", Age: 30} fmt.Println(reflect.ValueOf(p).String()) // prints "main.Person{Name:\"John Doe\", Age:30}" }This example shows how to get a string representation of a struct value using reflection. Package library: reflect.