相关疑难解决方法(0)

打印时如何用零填充数字?

如何打印数字或使用零填充制作字符串以使其固定宽度?

例如,如果我有这个号码12,我想制作它000012.

go

76
推荐指数
6
解决办法
6万
查看次数

Idiomatic way to Concat Leading Zeros in Go

I came up with a way to pad leading zeros into a Go string. I'm not sure if this is the way you do this in Go. Is there a proper way to do this in Go? This is what I came up with and can be found inside the second if block. I tried Google to see if it had something built in without luck.

func integerToStringOfFixedWidth(n int, w int) string {
  s := strconv.Itoa(n)
  l := len(s)

  if …
Run Code Online (Sandbox Code Playgroud)

idiomatic go leading-zero

1
推荐指数
1
解决办法
78
查看次数

标签 统计

go ×2

idiomatic ×1

leading-zero ×1