Convert DecimalField to String rather than Float
See original GitHub issueDecimalField entries are currently being converted to Float (https://github.com/graphql-python/graphene-django/blob/8f5a425859ea380d0640c441c5c7f3b1acae17b4/graphene_django/form_converter.py#L56-L59)
Full support for Decimal would be great, but in the meantime I propose that DecimalField should be converted to String instead. Once you’ve converted a Decimal to a Float, you’ve probably lost the benefit of why you used Decimal in the first place, since you’ll now have values like 3.14000000000000012
, rather than 3.14
. If it is converted to String, it is simple enough for the user to convert that String back to Decimal, whereas converting from Float to Decimal is not straightforward.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:17
- Comments:17
Top Results From Across the Web
Why Django DecimalField let me store Float or string?
A Decimal is more similar to an int than to a float. It's a fixed point integer, which is basically an integer with...
Read more >Decimal field conversions - InfoSphere DataStage - IBM
Decimal field conversions. By default InfoSphere® DataStage® converts decimal fields to and from all numeric data types and to and from string fields....
Read more >#8233 (Decimal Field can accept float value) – Django
The float value can be converted using the DecimalField format_number method, ... try: # if the value is a float, convert it to...
Read more >6 Ways to Convert String to Float in Python - FavTutor
Learn how to convert string to float in python in 6 different ways. ... deal with characters but instead, it works only with...
Read more >The Type Hierarchy - SQLAlchemy 1.4 Documentation
Default scale to use when converting from floats to Python decimals. ... and should instead implement TypeDecorator.process_bind_param() so ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a workaround for this particular problem, I created a Decimal type, and then am explicitly setting that field in the DjangoObjectType class. For example, I created a Decimal type like this
and then explicitly replace the field like this:
assuming that I have a Django model MyModel with Decimal field my_decimal_field.
Has this been documented in the changelog? It broke our existing app logic because now suddenly we started getting strings rather than floats. Is there a way to default to previous behavior?