0Pricing
Go Academy · Lesson

Type Conversions in Go

Explicit conversions, type aliases and defined types

Why Explicit Conversions?

Go never implicitly converts between types. This prevents subtle bugs where a small integer silently overflows a larger one or a float loses precision.

  • Conversions must be written explicitly: T(value)
  • The compiler catches mismatched types at compile time
  • This makes Go code predictable and safe

Numeric Conversions

Convert between numeric types with the target type as a function call:

package main

func main() {
    var i int = 42
    var f float64 = float64(i)
    var u uint = uint(f)
    _ = u
}

All lessons in this course

  1. Declaring Variables in Go
  2. Go's Built-in Types
  3. Constants and iota
  4. Type Conversions in Go
← Back to Go Academy