20 lines
375 B
Go
20 lines
375 B
Go
package conversion
|
|
|
|
import "errors"
|
|
import "strconv"
|
|
|
|
func StringsToFloats(strings []string) ([]float64, error) {
|
|
var floats []float64
|
|
|
|
for _, stringVal := range strings {
|
|
floatVal, err := strconv.ParseFloat(stringVal, 64)
|
|
|
|
if err != nil {
|
|
return nil, errors.New("Failed to convert string to float")
|
|
}
|
|
|
|
floats = append(floats, floatVal)
|
|
}
|
|
|
|
return floats, nil
|
|
} |