decimal_encoder
Encodes a Decimal as int if there's no exponent, otherwise float
def decimal_encoder(
dec_value: Decimal
) - > int | float
Encodes a Decimal as int if there's no exponent, otherwise float. This is useful when we use ConstrainedDecimal to represent Numeric(x,0) where an integer (but not int typed) is used. Encoding this as a float results in failed round-tripping between encode and parse. Our Id type is a prime example of this.
Parameters
| Name | Type | Description |
|---|---|---|
| dec_value | Decimal | The Decimal value to be encoded. |
Returns
| Type | Description |
|---|---|
| `int | float` |