Golang, Go : convert string to float number -
http://play.golang.org/p/7kr2uzlv5-
this playground link. have array of numbers in string. tried convert them float number not give me anything. wrong it?
var numbers []float64 _, elem := range str_numbers { i, err := strconv.parsefloat(elem, 64) if err != nil { numbers = append(numbers, i) } } fmt.println(numbers) // gives me nothing []
change
if err != nil {
to
if err == nil {
(you may doing already, unit testing great way catch bugs this.)
Comments
Post a Comment