Skip to content

Commit

Permalink
Fix reflection for numbers encoded as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj Jain authored and GregBowyer committed Jul 11, 2017
1 parent 10ef903 commit 311f370
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ func toNumber(value interface{}) (float64, bool) {
x = float64(value.(float32))
}
return x, true
case string:
var x float64
var err error
x, err = strconv.ParseFloat(value, 64)
if (err == nil) {
return x, true
} else {
return 0.0, false
}
case int, int8, int16, int32, int64:
i := reflect.ValueOf(value)
return float64(i.Int()), true
Expand Down

0 comments on commit 311f370

Please sign in to comment.