Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Possibility to remove trailing zeros on DecimalFields representation#6514
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 ourterms of service andprivacy 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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
stefanitsky commentedSep 9, 2020
@carltongibson merge, please 🤓 |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
PabloLefort commentedSep 13, 2020
Awesome work! What else do we need to merge this? Can I help in something? 🚀 |
sebabouche commentedNov 11, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I will love this feature. Will it be possible to apply it as a setting? Like |
Krolken commentedNov 12, 2020
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. |
amirmehdi left a comment
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
elongstreet88 commentedNov 23, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Is this PR still workable or did another workaround get put in place? |
Krolken commentedNov 24, 2021
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. |
martin056 commentedJul 12, 2022
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 :) |
Krolken commentedJul 12, 2022
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. |
Rjevski commentedNov 16, 2022
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
Uh oh!
There was an error while loading.Please reload this page.
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_outputoption on DecimalFields it would be possible to opt in on this behaviour and it wouldn't break other peoples code.Example use:
Fixes#6151