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
There is one simplest way to achieve this. Use
func padNumberWithZero(value uint32) string {
return fmt.Sprintf("%02d", value)
}
fmt.Sprintf formats and returns a string without printing it anywhere.
Here %02d says pad zero on left for value who has < 2 number of digits. If given value has 2 or more digits it will not pad. For example:
You can use %03d or more for more zeros padding.