-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Possibility to remove trailing zeros on DecimalFields representation #6514
Possibility to remove trailing zeros on DecimalFields representation #6514
Conversation
@carltongibson merge, please 🤓 |
Awesome work! What else do we need to merge this? Can I help in something? 🚀 |
I will love this feature. Will it be possible to apply it as a setting? Like
|
A default setting would be nice I'm waiting for the review to say all that I done so far is ok and can be merged. |
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.
this is so useful
Is this PR still workable or did another workaround get put in place? |
I don't think there is a solution for it yet. There might be a need for a rebase on master but mostly there is a need for a review and sign-off from the maintainers if this solution is favourable and something that should be included. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi all 👋 I also find this very useful. We've been adding some custom fields to achieve the same behavior in several projects so far. Is there any reason why this is not merged yet? I'd be happy to help if there is anything I could do :) |
Not really sure. I have been waiting for a comment from the maintainers. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Can we reopen this? It's also relevant for me - currently inlined the change into my client's codebase but would be nice to have this upstreamed so we can remove our local overrides. |
This isn't in any DRF release yet, but fixes typecheck in our CI. Upstream PR: encode/django-rest-framework#6514
Description
It would be good to have a way of remove trailing zeros in output. For example when working with a lot of decimal precision you now get very long strings when representing them as string in outputs.
This is good as a default. But mostly the string representation ends up in a json-response where we don't know how the receiver of the data handles the precision.
An option to trim trailing zeros would be good. It would reduce the amount of data you need to send and you wouldn't loose any data.
By using the decimal builtin
.normalize()
a decimal can be stripped of it rightmost trailing zeros. referenceBy introducing the
normalize_output
option on DecimalFields it would be possible to opt in on this behaviour and it wouldn't break other peoples code.Example use:
Fixes #6151