Using Python Decimal Type

I have a Model with a decimal.Decimal field that is being loaded into the state. However, the state does not display anything when the field is used as text in a component. For example, with the below model, I cannot display the decimal value.

class Data(rx.Model, table=True):
    id: str = sqlmodel.Field(primary_key=True)
    data: decimal.Decimal

class DataState(rx.State):
    data: list[Data]

Reflex ignores types that it doesn’t have a serializer for (that might be a bug), but in your case, you can define a Decimal serializer to convert the value into a float for the purposes of json serialization

@rx.serializer
def serialize_decimal(value: decimal.Decimal) -> float:
    return float(value)

This should treat the value like a number on the frontend as well, so you’ll have access to number-like operations when accessing the var from the frontend code.