dpoppu4300 2019-07-24 16:55
浏览 6261
已采纳

如何在Golang中将“ uint”类型转换为“ string”类型?

I'm working on a piece of code that returns uint data type. I need to convert uint datatype into string for further processing.

I've already tried strconv package and none of the functions accept uint. Golang Documentation: https://golang.org/ref/spec#Numeric_types states that uint are platform dependent. Is that the reason we don't have any standard functions for conversion?

type Example{
    Id uint    //value 3
    name string
}

Need to extract Id into a string.

Expected: "3" Actual: N/A

  • 写回答

1条回答 默认 最新

  • douwen9343 2019-07-24 16:59
    关注

    Use strconv.FormatUint():

    package main
    
    import (
        "fmt"
        "strconv"
    )
    
    func main() {
        var n uint = 123
        var s string = strconv.FormatUint(uint64(n), 10)
        fmt.Printf("s=%s
    ", s)
    }
    

    (Go Playground)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ /QT 内存权限的判断函数列举
  • ¥15 深度学习GFnet理解问题
  • ¥15 单细胞小提琴堆叠图代码
  • ¥80 LS dyna mpp并行报错
  • ¥50 升级strust2版本到2.3.15.1后使用ognl3.0.6.jar windows环境中没有问题,但部署到linux环境报错
  • ¥15 vue页面,node封装接口
  • ¥15 求TMS320F280039C工程模板!
  • ¥15 delphi+fastreport实现分组补空打印问题
  • ¥15 使用python把两台mysql数据库服务器数据导出和导入
  • ¥15 NodeBB论坛配置Apache Solr中文搜索引擎的详细教程