Wednesday, 1 May 2019

Go Language: Type Conversion


The expression T(v) converts the value v to the type T.

Example
var i int
var j float32 = 2.34
i = int(j)

App.go
package main

import "fmt"

func main() {
 var i int
 var j float32 = 2.34
 i = int(j)

 var k float32
 var l int = 2
 k = float32(l)

 fmt.Println("i = ", i)
 fmt.Println("j = ", j)

 fmt.Println("k = ", k)
 fmt.Println("l = ", l)

}

Output
i =  2
j =  2.34
k =  2
l =  2


Previous                                                 Next                                                 Home

No comments:

Post a Comment