How To Convert Integer To String In Go Lang | Go Language Examples | Java Inspires



 Hi Guys,

Welcome to Java Inspires .. in this post we will see how to convert a variable from integer type to string type.

goexample.go

package main

import (
	"fmt"
	"reflect"
	"strconv"
)

func main() {

	// lets start
	//To convert an integer to a string

	// create an int variable
	var int1 = 22
	// print the type of int1
	fmt.Println("int1 type :", reflect.TypeOf(int1))
	fmt.Println("Integer :", int1)

	// convert into string - using Itoa fron strconv
	var str1 = strconv.Itoa(int1)
	fmt.Println("str1 type :", reflect.TypeOf(str1))
	fmt.Println("String :", str1)

}

Output

PS D:\MyCode\go\example> go run .\goexample.go
int1 type : int
Integer : 22      
str1 type : string
String : 22       
PS D:\MyCode\go\example> 



Post a Comment

Previous Post Next Post