How to Use strconv.FormatUint() Function in Golang

Golang strconv.FormatUint() function is used to return the string representation of x in the given base, i.e., 2 <= base <= 36.

Syntax

func FormatUint(i uint64, base int) string

Parameters

  1. “i” is the unsigned integer value of type uint64 that you want to convert to a string representation.
  2. “base” is an int representing the base (radix) of the number system to use for the string representation (e.g., 2 for binary, 10 for decimal, 16 for hexadecimal).

Return value

It returns a string representing the given unsigned integer value in the specified base.

Example

package main

import (
  "fmt"
  "strconv"
)

func main() {
  var myUint uint = 123

  // Convert uint to string using strconv.FormatUint() with base 10 (decimal)
  myString := strconv.FormatUint(uint64(myUint), 10)

  fmt.Println("Converted uint to string:", myString)
}

Output

Converted uint to string: 123

Related posts

strconv.AppendQuoteRuneToGraphic()

strconv.AppendQuote()

strconv.AppendUint()

strconv.AppendQuoteRuneToASCII()

strconv.AppendInt()

strconv.ParseInt()