Data Types
Type Conversion
Go uses explicit conversions when a value needs a different type.
Type Conversion
type_conversion.go
package main
import "fmt"
func main() {
var whole =
half := float64(whole) / 2.0
label := fmt.Sprintf("%.1f", half)
fmt.Println("whole=", whole)
fmt.Println("half=", label)
}
package main
import "fmt"
func main() {
var whole =
half := float64(whole) / 2.0
label := fmt.Sprintf("%.1f", half)
fmt.Println("whole=", whole)
fmt.Println("half=", label)
}
package main
import "fmt"
func main() {
var whole =
half := float64(whole) / 2.0
label := fmt.Sprintf("%.1f", half)
fmt.Println("whole=", whole)
fmt.Println("half=", label)
}
type conversion
A conversion such as `float64(value)` creates a value of the target type.