Support for Decimal type
See original GitHub issueI’ve been using my own implementation of a Decimal type – maybe it should be included as a standard type?
from graphene.types import Scalar
from graphql.language import ast
class Decimal(Scalar):
"""
The `Decimal` scalar type represents a python Decimal.
"""
@staticmethod
def serialize(dec):
assert isinstance(dec, decimal.Decimal), (
'Received not compatible Decimal "{}"'.format(repr(dec))
)
return str(dec)
@staticmethod
def parse_value(value):
return decimal.Decimal(value)
@classmethod
def parse_literal(cls, node):
if isinstance(node, ast.StringValue):
return cls.parse_value(node.value)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Decimal Data Type - Visual Basic | Microsoft Learn
The Decimal data type provides the greatest number of significant digits for a number. It supports up to 29 significant digits and can ......
Read more >Decimal data type - Wikipedia
Language support C# has a built-in data type 'decimal', consisting of 128-bit resulting in 28-29 significant digits. It has an approximate Range of...
Read more >DECIMAL Data Type (Impala 3.0 or higher only)
The Impala DECIMAL type does not support negative values for precision. Parent topic: Data Types.
Read more >DECIMAL data type
DECIMAL data type ... DECIMAL provides an exact numeric in which the precision and scale can be arbitrarily sized. You can specify the...
Read more >decimal — Decimal fixed point and floating point arithmetic ...
The decimal module provides support for fast correctly rounded decimal floating point arithmetic. It offers several advantages over the float datatype:.
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
Ok, I will take a crack at it when I have a chance. I’ll have a look at the existing tests for other types for some examples.
(also it is there in the API documentation at least! https://docs.graphene-python.org/en/latest/api/#graphene-scalars)