Skip to content

Commit

Permalink
Fix PR #2 where "15.0" failed to be parsed into an integer field even…
Browse files Browse the repository at this point in the history
… though it is an integer.
  • Loading branch information
deslaughter committed Jul 19, 2024
1 parent dd699dc commit 20e5675
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fio.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,17 @@ func (fs *Files) parseFile(path string, s any) error {
v.Value = values[0]
case *Integer:
v.Value, err = strconv.Atoi(values[0])
if err != nil {
var f float64
f, err = strconv.ParseFloat(values[0], 64)
if err == nil {
if float64(int(f)) == f {
v.Value = int(f)
} else {
err = fmt.Errorf("%s cannot be converted to an integer", values[0])
}
}
}
case *Real:
v.Value, err = strconv.ParseFloat(values[0], 64)
case *Reals:
Expand Down

0 comments on commit 20e5675

Please sign in to comment.