gpt4 book ai didi

go - 将 strconv.ParseInt 与整数一起使用的惯用方法

转载 作者:IT王子 更新时间:2023-10-29 01:40:13 27 4
gpt4 key购买 nike

我最终会编写这样的代码。我需要一个常规的 int(用于其他一些函数调用),但 parseInt 只生成 64 位 int:

i64, err := strconv.ParseInt(s, 10, 0)
if err != nil {
fmt.Println("parsing failed for", s)
}
i := int(i64)

http://play.golang.org/p/_efRm7yp3o

有没有办法避免额外的转换?或者有什么方法可以让它更地道?

最佳答案

您可以使用 strconv.Atoi 以您想要的方式包装 strconv.ParseInt

关于go - 将 strconv.ParseInt 与整数一起使用的惯用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17659021/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com