[Go] Pad a number with leading zeros

Created on November 30, 2026

Use 0 and a minimum width in a format verb such as %08d. Here, fmt.Printf pads the number to eight digits.

package main

import "fmt"

func main() {
    fmt.Printf("%08d", 1)
}

Output

00000001
Go