OpenQuizz
Une application de gestion des contenus pédagogiques
Decimal Class Reference
Inheritance diagram for Decimal:
Collaboration diagram for Decimal:

Public Member Functions

def __init__ (self, typing.Optional[int] places=None, typing.Optional[str] rounding=None, *bool allow_nan=False, bool as_string=False, **kwargs)
 
- Public Member Functions inherited from Number
def __init__ (self, *bool as_string=False, **kwargs)
 
- Public Member Functions inherited from Field
None __init__ (self, *typing.Any default=missing_, typing.Any missing=missing_, typing.Optional[str] data_key=None, typing.Optional[str] attribute=None, typing.Optional[typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]],]] validate=None, bool required=False, typing.Optional[bool] allow_none=None, bool load_only=False, bool dump_only=False, typing.Optional[typing.Dict[str, str]] error_messages=None, typing.Optional[typing.Mapping[str, typing.Any]] metadata=None, **additional_metadata)
 
str __repr__ (self)
 
def __deepcopy__ (self, memo)
 
def get_value (self, obj, attr, accessor=None, default=missing_)
 
ValidationError make_error (self, str key, **kwargs)
 
def fail (self, str key, **kwargs)
 
def serialize (self, str attr, typing.Any obj, typing.Optional[typing.Callable[[typing.Any, str, typing.Any], typing.Any]] accessor=None, **kwargs)
 
def deserialize (self, typing.Any value, typing.Optional[str] attr=None, typing.Optional[typing.Mapping[str, typing.Any]] data=None, **kwargs)
 
def context (self)
 
- Public Member Functions inherited from FieldABC
def serialize (self, attr, obj, accessor=None)
 
def deserialize (self, value)
 

Data Fields

 places
 
 rounding
 
 allow_nan
 
- Data Fields inherited from Number
 as_string
 
- Data Fields inherited from Field
 default
 
 attribute
 
 data_key
 
 validate
 
 validators
 
 allow_none
 
 load_only
 
 dump_only
 
 required
 
 missing
 
 metadata
 
 error_messages
 
 parent
 
 name
 
 root
 

Static Public Attributes

 num_type
 
 default_error_messages
 
- Static Public Attributes inherited from Number
 num_type
 
 default_error_messages
 
- Static Public Attributes inherited from Field
 default_error_messages
 
- Static Public Attributes inherited from FieldABC
 parent
 
 name
 
 root
 

Detailed Description

A field that (de)serializes to the Python ``decimal.Decimal`` type.
It's safe to use when dealing with money values, percentages, ratios
or other numbers where precision is critical.

.. warning::

    This field serializes to a `decimal.Decimal` object by default. If you need
    to render your data as JSON, keep in mind that the `json` module from the
    standard library does not encode `decimal.Decimal`. Therefore, you must use
    a JSON library that can handle decimals, such as `simplejson`, or serialize
    to a string by passing ``as_string=True``.

.. warning::

    If a JSON `float` value is passed to this field for deserialization it will
    first be cast to its corresponding `string` value before being deserialized
    to a `decimal.Decimal` object. The default `__str__` implementation of the
    built-in Python `float` type may apply a destructive transformation upon
    its input data and therefore cannot be relied upon to preserve precision.
    To avoid this, you can instead pass a JSON `string` to be deserialized
    directly.

:param places: How many decimal places to quantize the value. If `None`, does
    not quantize the value.
:param rounding: How to round the value during quantize, for example
    `decimal.ROUND_UP`. If `None`, uses the rounding value from
    the current thread's context.
:param allow_nan: If `True`, `NaN`, `Infinity` and `-Infinity` are allowed,
    even though they are illegal according to the JSON specification.
:param as_string: If `True`, serialize to a string instead of a Python
    `decimal.Decimal` type.
:param kwargs: The same keyword arguments that :class:`Number` receives.

.. versionadded:: 1.2.0

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
typing.Optional[int]   places = None,
typing.Optional[str]   rounding = None,
*bool   allow_nan = False,
bool   as_string = False,
**  kwargs 
)

Field Documentation

◆ allow_nan

allow_nan

◆ default_error_messages

default_error_messages
static

◆ num_type

num_type
static

◆ places

places

◆ rounding

rounding

The documentation for this class was generated from the following file: