/** * Casting in go from string to int is not allowed via the * casting operators. However, you can do a converting * cast using strconv.Atoi * OTOH, converting case from float to int is allowed. * * Author: gtowell * Created: July 2022 **/ package main import ( "fmt" "strconv" ) func t5() { str := "abc" str123 := "123" flo := 123.456 fmt.Println(str) var num int num=40 fmt.Println(num) num = int(str) // Compiler flags as not allowed num = int(str123) // also not allowed by compiler num = int(flo) num, _ = strconv.Atoi(str) num, _ = strconv.Atoi(str123) } func main() { t5() }