Created
April 7, 2015 01:10
-
-
Save btc/b17557b788c22fdc59ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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