我正在尝试打印 string
和 uint64
但没有组合 strconv
我使用的方法有效。
log.Println("The amount is: " + strconv.Itoa((charge.Amount)))
给我:
cannot use charge.Amount (type uint64) as type int in argument to strconv.Itoa
我怎样才能打印这个 string
?
原文由 Anthony 发布,翻译遵循 CC BY-SA 4.0 许可协议
strconv.Itoa()
需要一个类型为int
的值,所以你必须给它:但是要知道,如果
int
是 32 位(而uint64
是 64),这可能会失去精度,符号也不同。strconv.FormatUint()
会更好,因为它期望类型为uint64
的值:有关更多选项,请参阅此答案: Golang: format a string without printing?
如果您的目的只是打印该值,则不需要将其转换为
int
或string
,使用以下之一: