简体   繁体   English

将[] uint8转换为float64

[英]Converting []uint8 to float64

What is the best way to handle an http resp.Body which is formatted as []uint8 and not as JSON? 处理http resp.Body的最佳方法是什么,格式为[]uint8而不是JSON? I would like to convert the bytes into a float64 . 我想将字节转换为float64

This is the returned value response: 这是返回值响应:

value : %!F([]uint8=[48 46 48 48 49 50 53 53 50 49])

Try using ParseFloat from the strconv package ( play ): 尝试使用ParseFloat包中的strconv播放 ):

b := []uint8{48, 46, 48, 48, 49, 50, 53, 53, 50, 49}

f, err := strconv.ParseFloat(string(b), 64)

if err != nil { 
    // Handle parse error
}

fmt.Printf("%f\n", f) // 0.001255

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM