Latest web development tutorials

Go language type conversions

Type conversion for a variable of one data type to another type of variable. Go language casts the basic format is as follows:

type_name(expression)

type_name the type, expression of expression.

Examples

The following examples will be converted to floating point integer, and calculate the results, the results will be assigned to the float variable:

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)
}

Examples of the implementation of the above output is:

mean 的值为: 3.400000