如何用零填充数字?

Kev*_*rke 0 go

假设我想在Go中输出一个数字:

4 => "004"
23 => "023"
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

Kev*_*rke 12

使用来自fmt包"%0xd"标志,其中是要填充的前导零的数量.fmt.Printfx

import "fmt"
fmt.Printf("%03d", 4)    // will print "004"
Run Code Online (Sandbox Code Playgroud)

界面与C中的相同.