-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Normalizer
: float
precision
#476
Comments
Hi @boesing, sorry I took that long to come back to you. I'm wondering if we should not just force
Do you think it would make sense as a default behavior? |
All good, this is how OSS works. No demanding from my side 🤙🏼
For me that would work, but no clue if other projects using valinor do actually depend on the fact that the zero fraction is dropped. 😅 I am actually trying to implement an optional argument to Just need to find out how to pass these to the Thoughts? |
🤗
The container is completely closed to any modification to reduce the maintenance burden. 😉 IMO, some of (new \CuyZ\Valinor\MapperBuilder())
->normalizer(\CuyZ\Valinor\Normalizer\Format::json())
->withOptions(JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_SLASHES)
->normalize(/* … */); This is the white list that makes sense to me, WDYT?
|
Sounds reasonable to me. I can prepare a PR 👍🏻 |
Would be wonderful! |
Hm, I realize that there is only So it seems that it should also use |
Just saw your comment although I already posted code-review of #512. 😬 When you write about "object properties" I guess what you mean is "keys"? If that's it, then yes I believe the JSON formatter should stick to the native behavior. This can be done here: Will you have time to update #512? If not I'll take care of it. 😉 |
I might find some time next weekend, but not sure yet. Feel free to take over in case you find some spare time before I do |
Hey there,
as we already had issues in valinor regarding
float
andint
strict comparison, I wanted to bring this topic up.I am not sure how different languages handle this, but I would assume that
int
can be afloat
as well, however, to prevent that, we sometimes usedJSON_PRESERVE_ZERO_FRACTION
.Valinors
JsonNormalizer
is just casting floats to string which drops the zero fraction and converts floats toint
in case they do not have decimals.Should we either add a way to enable this behavior or is this ignored on purpose?
Current workaround is to use the array normalizer and
json_encode
on our own in combination withJSON_PRESERVE_ZERO_FRACTION
.The text was updated successfully, but these errors were encountered: