How to format an integer with zero-padding in Go

1 Answer

0 votes
package main

import (
    "fmt"
)

func main() {
    number := 319

    // Format with leading zeros to 6 digits
    formatted := fmt.Sprintf("%06d", number)

    fmt.Println(formatted)
}



/*
run:

000319

*/

 



answered Jun 19, 2025 by avibootz

Related questions

...