diff --git a/README.md b/README.md index 09b36e2..1f8b5e7 100644 --- a/README.md +++ b/README.md @@ -73,4 +73,5 @@ Currently this library supports limited fields - int - string - bool +- float64 diff --git a/parser.go b/parser.go index b2e29e1..785e993 100644 --- a/parser.go +++ b/parser.go @@ -3,10 +3,11 @@ package tsv import ( "encoding/csv" "errors" - "golang.org/x/text/unicode/norm" "io" "reflect" "strconv" + + "golang.org/x/text/unicode/norm" ) // Parser has information for parser @@ -152,6 +153,16 @@ func (p *Parser) Next() (eof bool, err error) { } field.SetInt(col) } + case reflect.Float64: + if record == "" { + field.SetFloat(0) + } else { + col, err := strconv.ParseFloat(record, -1) + if err != nil { + return false, err + } + field.SetFloat(col) + } default: return false, errors.New("Unsupported field type") }