-
Notifications
You must be signed in to change notification settings - Fork 154
Add NumberFormatStrategy for Floating Points. Add option for decimal Encoding/Decoding #452
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
base: main
Are you sure you want to change the base?
Conversation
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.
I think this enhancement would be much more useful, much more future-forward and much easier to maintain if we simply introduced an optional NumberFormatter
(Foundation) to the Emitter Options.
Not a problem, what do you think about maximumFractionDigitsNumber for Float/Double? I think, I can take JSONDecoder behavior for that.. I will be back soon with a new commit. |
Unfortunately, I stuck with problem to formatting FloatingPoint.greatestFiniteMagnitude, because we should to use exponential value here, but NSNumberFormatter can't be configurated in this way. I look into JSONEncoder and noticed that they use If value is greatestFiniteMagnitude -> use exponential, otherwise use human readable decimal. I update Represented.swift that will use that new rule and it's looks more readable and maintainable than my previous commits. What do you think? |
sequenceStyle: encoder.sequenceStyle, | ||
mappingStyle: encoder.mappingStyle, | ||
newlineScalarStyle: encoder.newlineScalarStyle) | ||
options: encoder.options) |
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.
Yes to passing the options struct. 👏
@@ -62,40 +62,40 @@ private func represent(_ value: Any) throws -> Node { | |||
/// Type is representable as `Node.scalar`. | |||
public protocol ScalarRepresentable: NodeRepresentable { | |||
/// This value's `Node.scalar` representation. | |||
func represented() -> Node.Scalar | |||
func represented(options: Emitter.Options) -> Node.Scalar |
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.
I don't think that changing the ScalarRepresentable protocol is called for. It's a breaking change.
Isn't there another way?
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.
Hmmm, I will double check this.
Closes #279
I modified PR by zeionara - #374
For my project https://github.com/AdaEngine/AdaEngine needs a human readable Floating Points values and I want to fix exponential values in yaml files.
I've add a tests for Float and Double, and I hope we merge this request.
Thank you for your project!