How can I print a number or make a string with zero padding to make it fixed width?
For instance, if I have the number 12 and I want to make it 00
12
00
The fmt package can do this for you:
fmt.Printf("|%06d|%6d|\n", 12, 345)
Output:
|000012| 345|
Notice the 0 in %06d, that will make it a width of 6 and pad it with zeros. The second one will pad with spaces.
Try it for yourself here: http://play.golang.org/p/cinDspMccp