Go Language Type Conversion
Type conversion is used to convert a variable of one data type to another type. The basic format for type conversion in Go is as follows:
type_name(expression)
type_name
is the type, and expression
is the expression.
Example
In the following example, an integer is converted to a float, and the result is calculated and assigned to a float variable:
Example
package main
import "fmt"
func main() {
var sum int = 17
var count int = 5
var mean float32
mean = float32(sum)/float32(count)
fmt.Printf("mean 的值为: %f\n",mean)
}
The output of the above example is:
mean 的值为: 3.400000