Type conversion is used to convert a variable of one data type to another. The basic format of
Go
language type conversion is as follows:
type_name(expression)
In the following example, an integer is converted to a floating-point type, the result is calculated, and the result is assigned to a floating-point variable: The output of the above example is as follows:
type_name
is the type,
expression
is an expression. 2.41.1. Example #
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("The value of mean is: %f\\n",mean)
}
The value of mean is: 3.400000