How to convert an int value to string in Go ?

How to convert an int value to string in Go ?

Asked on December 19, 2018 in String.
Add Comment


  • 3 Answer(s)

    Using strconv  function.

    Try this code:

    package main
     
    import (
        "strconv"
        "fmt"
    )
     
    func main() {
        t := strconv.Itoa(123)
        fmt.Println(t)
    }
     
    

    Now  contact strings  by using the Join function of the strings package.

    Answered on December 19, 2018.
    Add Comment
    fmt.Sprintf("%v",value);
    

    Also  use the comparable formats like  %d for int

    For more information check here – fmt

    Answered on December 19, 2018.
    Add Comment

    Here is exotic solution  to note that strconv.Itoa :

    func FormatInt(i int64, base int) string
    

    with base 10

    such as:

    strconv.Itoa(123)
    

    is equal to

    strconv.FormatInt(int64(123), 10)
    
    Answered on December 19, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.