请教下字符串转float的问题

zhong · · 1071 次点击
example ```go package main import ( "fmt" "strconv" ) func main() { stringA := "34.56213" stringB := "78.90455" floatA, err := strconv.ParseFloat(stringA, 64) if err != nil { panic(err) } floatB, err := strconv.ParseFloat(stringB, 64) if err != nil { panic(err) } floatSum := floatA + floatB stringSum := strconv.FormatFloat(floatSum, 'f', 5, 64) fmt.Println(stringSum) } ``` 具体用法参考文档:https://golang.org/pkg/strconv/#pkg-index
#1