added result.Uint() function resolves #9

This commit is contained in:
Josh Baker 2016-11-02 08:24:13 -07:00
parent 78babc5712
commit a02d704254
2 changed files with 16 additions and 0 deletions

View File

@ -119,6 +119,7 @@ There are a variety of handy functions that work on a result:
```go
result.Value() interface{}
result.Int() int64
result.Uint() uint64
result.Float() float64
result.String() string
result.Bool() bool

View File

@ -108,6 +108,21 @@ func (t Result) Int() int64 {
}
}
// Uint returns an unsigned integer representation.
func (t Result) Uint() uint64 {
switch t.Type {
default:
return 0
case True:
return 1
case String:
n, _ := strconv.ParseUint(t.Str, 10, 64)
return n
case Number:
return uint64(t.Num)
}
}
// Float returns an float64 representation.
func (t Result) Float() float64 {
switch t.Type {