Golang - How to fetch an Integer variable as String? Code Example

The code for How to fetch an Integer variable as String?

// Go language program to fetch an Integer variable as string

package main

import (
	"fmt"
	"strconv"
)

func main() {

	var value int
	value = 36

	// Itoa() - conversion from int to string.
	res1 := strconv.Itoa(value)
	fmt.Printf("%T %v\n", res1, res1)

	// format 36 int base 10 -> 36
	res2 := strconv.FormatInt(int64(value), 10)
	fmt.Printf("%T %v\n", res2, res2)

	// return string representation
	// of 36 in base 10 -> 36
	res3 := strconv.FormatUint(uint64(value), 10)
	fmt.Printf("%T %v\n", res3, res3)

	// concatenating all string->res1,res2 and res3.
	fmt.Println("Concatenating all strings: ", res1+res2+res3)
}


/*
Output:
string 36
string 36
string 36
Concatenating all strings:  363636
*/
Code by IncludeHelp, on March 1, 2023 07:32

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.