Skip to content

Commit

Permalink
Fix float formatting (#2018)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenseng committed Oct 13, 2023
1 parent 99067a9 commit ace4cd4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/exprparser/functions_test.go
Expand Up @@ -230,6 +230,7 @@ func TestFunctionFormat(t *testing.T) {
{"format('{0', '{1}', 'World')", nil, "Unclosed brackets. The following format string is invalid: '{0'", "format-invalid-format-string"},
{"format('{2}', '{1}', 'World')", "", "The following format string references more arguments than were supplied: '{2}'", "format-invalid-replacement-reference"},
{"format('{2147483648}')", "", "The following format string is invalid: '{2147483648}'", "format-invalid-replacement-reference"},
{"format('{0} {1} {2} {3}', 1.0, 1.1, 1234567890.0, 12345678901234567890.0)", "1 1.1 1234567890 1.23456789012346E+19", nil, "format-floats"},
}

env := &EvaluationEnvironment{
Expand Down
2 changes: 1 addition & 1 deletion pkg/exprparser/interpreter.go
Expand Up @@ -447,7 +447,7 @@ func (impl *interperterImpl) coerceToString(value reflect.Value) reflect.Value {
} else if math.IsInf(value.Float(), -1) {
return reflect.ValueOf("-Infinity")
}
return reflect.ValueOf(fmt.Sprint(value))
return reflect.ValueOf(fmt.Sprintf("%.15G", value.Float()))

case reflect.Slice:
return reflect.ValueOf("Array")
Expand Down

0 comments on commit ace4cd4

Please sign in to comment.