route:= this.GetString("route")
hight:= this.GetString("hight")
bridge:= this.GetString("bridge")
oil:= this.GetString("oil")
// total:= this.GetString("Total")
// var total=hight+bridge+oil
// var total=strconv.Atoi(hight)+strconv.Atoi(bridge)+strconv.Atoi(oil)
var total, err = strconv.ParseFloat(hight, '10', -1, 32)+strconv.ParseFloat(bridge, '10', -1, 32)
▶ 0003 Failed to build the application: # opms/controllers/financial
controllers\financial\financial.go:160:6: err redeclared in this block
previous declaration at controllers\financial\financial.go:140:5
controllers\financial\financial.go:160:37: too many arguments in call to strconv.ParseFloat
have (string, number, number, number)
want (string, int)
controllers\financial\financial.go:160:37: multiple-value strconv.ParseFloat() in single-value context
controllers\financial\financial.go:160:45: invalid character literal (more than one character)
controllers\financial\financial.go:160:77: too many arguments in call to strconv.ParseFloat
have (string, number, number, number)
want (string, int)
controllers\financial\financial.go:160:77: multiple-value strconv.ParseFloat() in single-value context
求教各位大神,如何把字符串的转成float的小数相加后再转换回字符串,谢谢
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