Skip to content

Instantly share code, notes, and snippets.

@btc
Created April 7, 2015 01:10
Show Gist options
  • Select an option

  • Save btc/b17557b788c22fdc59ea to your computer and use it in GitHub Desktop.

Select an option

Save btc/b17557b788c22fdc59ea to your computer and use it in GitHub Desktop.
package main
import (
"encoding/csv"
"fmt"
"io"
"log"
"os"
"strconv"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
r, err := os.Open("orders.csv")
if err != nil {
return err
}
csvr := csv.NewReader(r)
var total float64
for {
rec, err := csvr.Read()
if err == io.EOF {
break
}
if err != nil {
return err
}
fmt.Println(rec[20])
if len(rec[20]) < 1 {
continue
}
amt, err := strconv.ParseFloat(rec[20][1:], 64)
if err != nil {
log.Println(err)
continue
}
fmt.Println(amt)
total += amt
}
fmt.Println(total)
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment