Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into duration
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinmit committed Aug 24, 2021
2 parents f50bfef + e2008a9 commit 0206999
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (e *Encoder) encodeFloat(v float64, bitSize int) ast.Node {
return ast.Nan(token.New(value, value, e.pos(e.column)))
}
value := strconv.FormatFloat(v, 'g', -1, bitSize)
if !strings.Contains(value, ".") {
if !strings.Contains(value, ".") && !strings.Contains(value, "e") {
// append x.0 suffix to keep float value context
value = fmt.Sprintf("%s.0", value)
}
Expand Down
5 changes: 5 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func TestEncoder(t *testing.T) {
map[string]float64{"v": 1.0},
nil,
},
{
"v: 1e+06\n",
map[string]float64{"v": 1000000},
nil,
},
{
"v: .inf\n",
map[string]interface{}{"v": math.Inf(0)},
Expand Down

0 comments on commit 0206999

Please sign in to comment.