【发布时间】:2023-04-02 10:42:02
【问题描述】:
我想将大整数格式化为带有前导零的字符串。我正在寻找类似于this 的示例,但使用 Big:
我正在查看源代码here。
但是当我打电话时:
m := big.NewInt(99999999999999)
fmt.Println(m.Format("%010000000000000000000","d"))
我明白了:
prog.go:10:22: m.Format("%010000000000000000000", "d") used as value
prog.go:10:23: cannot use "%010000000000000000000" (type string) as type fmt.State in argument to m.Format:
string does not implement fmt.State (missing Flag method)
prog.go:10:48: cannot use "d" (type string) as type rune in argument to m.Format
(我通常理解我可以使用 m.String(),但零填充似乎会使这复杂化,所以我正在寻找有关 Format 方法的一些帮助。)
【问题讨论】:
-
谢谢大家。我只是忘记了 Sprintf。 ://
标签: string go string-formatting