Type Casting or Type Conversion in Golang Last Updated : 14 Mar, 2023 Comments Improve Suggest changes Like Article Like Report Prerequisite: Golang Data Types Type conversion happens when we assign the value of one data type to another. Statically typed languages like C/C++, Java, provide the support for Implicit Type Conversion but Golang is different, as it doesn't support the Automatic Type Conversion or Implicit Type Conversion even if the data types are compatible. The reason for this is the Strong Type System of the Golang which doesn't allow to do this. For type conversion, you must perform explicit conversion. As per Golang Specification, there is no typecasting word or terminology in Golang. If you will try to search Type Casting in Golang Specifications or Documentation, you will find nothing like this. There is only Type Conversion. In Other programming languages, typecasting is also termed as the type conversion.What is the need for Type Conversion? Well, if you need to take advantage of certain characteristics of data type hierarchies, then we have to change entities from one data type into another. The general syntax for converting a value val to a type T is T(val). Example: var geek1 int = 845 // explicit type conversion var geek2 float64 = float64(geek1) var geek3 int64 = int64(geek1) var geek4 uint = uint(geek1) Go // Go program to find the // average of numbers package main import "fmt" func main() { // taking the required // data into variables var totalsum int = 846 var number int = 19 var avg float32 // explicit type conversion avg = float32(totalsum) / float32(number) // Displaying the result fmt.Printf("Average = %f\n", avg) } Output: Average = 44.526318 Note: As Golang has a strong type system, it doesn't allow to mix(like addition, subtraction, multiplication, division, etc.) the numeric types in the expressions and also you are not allowed to perform an assignment between the two mixed types.Example: var geek1 int64 = 875 // it will give compile time error as we // are performing an assignment between // mixed types i.e. int64 as int type var geek2 int = geek1 var geek3 int = 100 // it gives compile time error // as this is invalid operation // because types are mix i.e. // int64 and int var addition = geek1 + geek3 Comment More infoAdvertise with us Next Article Type Casting or Type Conversion in Golang A anita yadav Follow Improve Article Tags : Go Language Go-Basics Golang Similar Reads Type Assertions in Golang Type assertions in Golang provide access to the exact type of variable of an interface. If already the data type is present in the interface, then it will retrieve the actual data type value held by the interface. A type assertion takes an interface value and extracts from it a value of the specifie 2 min read reflect.Type() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Type() Function in Golang is used to get v's type. To access this function, one needs to imports the reflect pack 1 min read Different Ways to Convert the Boolean Type in String in Golang In order to convert Boolean Type to String type in Golang , you can use the strconv and fmt package function. 1. strconv.FormatBool() Method: The FormatBool is used to Boolean Type to String. It returns "true" or "false" according to the value of b. Syntax: func FormatBool(b bool) string Example : C 2 min read reflect.TypeOf() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package.The reflect.TypeOf() Function in Golang is used to get the reflection Type that represents the dynamic type of i. To access th 1 min read Go Type Assertion vs Type Switches Type Assertion allows you to access the underlying concrete type of an interface. When you have a variable of type interface{}, you might want to access its actual type (the type it holds), and Type Assertion helps with that.Differences Between Type Assertion and Type SwitchFeatureType AssertionType 5 min read Like