Avatar ·

How to print a number with leading zeros in Go?

Hello everyone! I just started learning Go and encountered this problem. I need to print a number, for example 7, in a format with leading zeros, so that it becomes "0007" (4 characters total). I've tried a bunch of options, but nothing works. Here's what I tried: ```go package main import "fmt" func main() { num := 7 fmt.Println("Result: " + num) // Error: cannot convert num to string fmt.Println("Result: " + string(num)) // Prints some gibberish } ``` I'm used to being able to just write `f"{num:04d}"` in Python, or `printf("%04d", num)` in C. But in Go I can't find an equivalent. I tried using `strconv.Itoa(num)`, but it just converts the number to a string without formatting. I need: - Number 7 to become "0007" - Number 123 to become "01