Skip to content

Commit

Permalink
Flatten(): render even large numbers as-is, not using scientific nota…
Browse files Browse the repository at this point in the history
…tion

E.g. 2000000000000000000 (explicitly), not 2e+18 (as with fmt.Sprintf("%v")).
  • Loading branch information
Al2Klimov committed Mar 25, 2024
1 parent 365f97d commit 17b63b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/flatten/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions pkg/flatten/flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}}},
Expand Down

0 comments on commit 17b63b2

Please sign in to comment.