将[] uint8转换为float64

Ale*_*lex 3 type-conversion go

处理resp.Body格式化[]uint8而不是JSON 格式的http的最佳方法是什么?我想将字节转换为a float64.

这是返回值响应:

value : %!F([]uint8=[48 46 48 48 49 50 53 53 50 49])
Run Code Online (Sandbox Code Playgroud)

nem*_*emo 5

尝试使用ParseFloatstrconv包(播放):

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
Run Code Online (Sandbox Code Playgroud)