diff --git a/pkg/jq/jq.go b/pkg/jq/jq.go index 5f19e1f..d49e3f5 100644 --- a/pkg/jq/jq.go +++ b/pkg/jq/jq.go @@ -104,7 +104,7 @@ func jsonScalarToString(input interface{}) (string, error) { if math.Trunc(tt) == tt { return strconv.FormatFloat(tt, 'f', 0, 64), nil } else { - return strconv.FormatFloat(tt, 'f', 2, 64), nil + return strconv.FormatFloat(tt, 'f', -1, 64), nil } case nil: return "", nil diff --git a/pkg/jq/jq_test.go b/pkg/jq/jq_test.go index 1264de9..4dc5b72 100644 --- a/pkg/jq/jq_test.go +++ b/pkg/jq/jq_test.go @@ -172,6 +172,16 @@ func TestEvaluateFormatted(t *testing.T) { " \x1b[32m\"bar\"\x1b[m\n" + "\x1b[1;38m}\x1b[m\n", }, + { + name: "non-integer numbers keep full precision", + args: args{ + json: strings.NewReader(`{"pi": 3.14159, "small": 0.001, "big": 123456.789}`), + expr: `.pi, .small, .big`, + indent: "", + colorize: false, + }, + wantW: "3.14159\n0.001\n123456.789\n", + }, { name: "halt function", args: args{