From 17b63b214d68e7bad3b5b27382f5457ac01a28e2 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 25 Mar 2024 13:30:39 +0100 Subject: [PATCH] Flatten(): render even large numbers as-is, not using scientific notation E.g. 2000000000000000000 (explicitly), not 2e+18 (as with fmt.Sprintf("%v")). --- pkg/flatten/flatten.go | 2 ++ pkg/flatten/flatten_test.go | 1 + 2 files changed, 3 insertions(+) diff --git a/pkg/flatten/flatten.go b/pkg/flatten/flatten.go index 127cbfbde..698eff178 100644 --- a/pkg/flatten/flatten.go +++ b/pkg/flatten/flatten.go @@ -33,6 +33,8 @@ func Flatten(value interface{}, prefix string) map[string]types.String { } case nil: flattened[key] = types.MakeString("null") + case float64: + flattened[key] = types.MakeString(strconv.FormatFloat(value, 'f', -1, 64)) default: flattened[key] = types.MakeString(fmt.Sprintf("%v", value)) } diff --git a/pkg/flatten/flatten_test.go b/pkg/flatten/flatten_test.go index 0655550f1..f84b8d9ec 100644 --- a/pkg/flatten/flatten_test.go +++ b/pkg/flatten/flatten_test.go @@ -17,6 +17,7 @@ func TestFlatten(t *testing.T) { {"bool", "b", true, map[string]types.String{"b": types.MakeString("true")}}, {"int", "c", 42, map[string]types.String{"c": types.MakeString("42")}}, {"float", "d", 77.7, map[string]types.String{"d": types.MakeString("77.7")}}, + {"large_float", "e", 1e23, map[string]types.String{"e": types.MakeString("100000000000000000000000")}}, {"string", "f", "\x00", map[string]types.String{"f": types.MakeString("\x00")}}, {"nil_slice", "g", []any(nil), map[string]types.String{"g": {}}}, {"empty_slice", "h", []any{}, map[string]types.String{"h": {}}},