-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow setting floating point precision in JSON #663
Conversation
encoder_json.go
Outdated
@@ -21,6 +21,9 @@ func init() { | |||
json.JSONMarshalFunc = func(v interface{}) ([]byte, error) { | |||
return InterfaceMarshalFunc(v) | |||
} | |||
json.FloatingPointPrecisionFunc = func() int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this func needed?
internal/json/types.go
Outdated
@@ -311,16 +311,20 @@ func appendFloat(dst []byte, val float64, bitSize int) []byte { | |||
case math.IsInf(val, -1): | |||
return append(dst, `"-Inf"`...) | |||
} | |||
precision := FloatingPointPrecisionFunc() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would make more sense to pass the precision as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was not able to set this as a global variable because that would introduce an import loop.
If you are OK with that, I can introduce a parameter to appendFloat
and then pass it everywhere it is called.
46f6a64
to
22fc3a9
Compare
@rs: Pushed with the argument. |
Thanks. Last thing, can you please document it in the README? |
@rs: Done. |
Fixes #557.