Skip to content

Instantly share code, notes, and snippets.

@GhazeyAhmed
Created May 22, 2022 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GhazeyAhmed/fb62913c1b905727810731b1bc67aa30 to your computer and use it in GitHub Desktop.
Save GhazeyAhmed/fb62913c1b905727810731b1bc67aa30 to your computer and use it in GitHub Desktop.
Get Floats Defer
func GetFloats(fileName string)([]float64, error){
var numbers []float64
file, err := OpenFile(fileName)
if err != nil {
return nil, err
}
defer CloseFile(file)
scanner := bufio.NewScanner(file)
for scanner.Scan(){
number, err := strconv.ParseFloat(scanner.Text(), 64)
if err != nil {
return nil, err
}
numbers = append(numbers, number)
}
if scanner.Err() != nil{
return nil, scanner.Err()
}
return numbers, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment