strconv.FormatInt() functionThe strconv package’s FormatInt() function is used to obtain the string representation of a given integer in a chosen base, which can range from 2 to 36 (2 <= base <= 36). For digit values greater >= 10, the output uses lower-case letters a to z.
func FormatInt(i int64, base int) string
i: The integer value to be converted in the string format.base: The given base value.The function FormatInt() returns the string representation of the given integer in the given base.
The following code shows how to implement the strconv.FormatInt() function in Go.
// Using strconv.FormatFloat() Functionpackage mainimport ("fmt""strconv")func main() {// declaring variablevar num int64// Assign valuenum = 2634// returns a string typefmt.Println(strconv.FormatInt(num, 10))fmt.Println()// reassign valuenum = 186// returns a string typefmt.Println(strconv.FormatInt(num, 2))fmt.Println()// reassign valuenum = 86// returns a string typefmt.Println(strconv.FormatInt(num, 16))fmt.Println()}
main package.main() function, variable num of int64 type, and assign a value to it. Next, we pass the variable to the FormatInt() function, which converts the integer value to a string given the base parameter.