golang tutorial - Golang Typecasting | Type Casting In Golang - golang - go programming language - google go - go language - go program - google language
Golang Typecasting
- Type conversion, type casting, and type coercion are different ways of changing an variable from one data type into another.
- An example would be the conversion of an integer value into a floating point value
- Type conversions can take advantage of certain features of type hierarchies or data representations.
- Two important aspects of a type conversion is
- Implicitly
- Explicitly,
- You can convert values from one type to another using the cast operator as following:
type_name(expression)
click below button to copy the code. By - golang tutorial - team

Type Casting in golang programming
Example
package main
import "fmt"
func main() {
var a int = 8
var b int = 3
var c float32
c = float32(a)/float32(b)
fmt.Printf("Value of c : %f\n",mean)
}
click below button to copy the code. By - golang tutorial - team
golang , gopro , google go , golang tutorial , google language , go language , go programming language
Output for the above go program
Value of c : 2.66666

Type Casting in golang programming