我试图将字符串切片转换为浮点数,但结果不是切片。有没有办法将字符串切片中的元素转换为 float64 以返回 float64 切片?
func main() {
a := []string{"20.02", "30.01"}
fmt.Println("This is a single slice of string:", a)
for i, element := range a {
element, _ := strconv.ParseFloat(element, 64)
//This result converts each element to float64 but no longer holds them in a slice.
fmt.Printf("%v, %v\n", i, element)
}
Run Code Online (Sandbox Code Playgroud)
}