You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
Passing a string with leading or trailing string to ParseFloat, ParseFloat doesn't give
the float number but raises errors for last three strings
in code show at
http://play.golang.org/p/9R7YUJm_a2
package main
import "fmt"
import "strconv"
import "strings"
func main() {
fs := [...]string{"1.2", " 1.2", "1.2 ", " 1.2 "}
for pos, str := range fs {
f, err := strconv.ParseFloat(str, 64)
fmt.Println(pos, str, f, err)
}
for pos, str := range fs {
f, err := strconv.ParseFloat(strings.TrimSpace(str), 64)
fmt.Println(pos, str, f, err)
}
}
What is the expected output?
Leading and trailing spaces should be allowed as in most other languages I have known.
No error should be raise.
What do you see instead?
ParseFloat raise errors for the last three strings
Which version are you using? (run 'go version')
go1.0.2
Allowance of leading/trailing space is a great convenience to deal with fixed format
data file, otherwise TrimSpace always had to be called.
The text was updated successfully, but these errors were encountered:
by qsb300:
The text was updated successfully, but these errors were encountered: