type_bridge.attribute.decimal¶
decimal
¶
Decimal attribute type for TypeDB.
Decimal
¶
Bases: NumericAttribute
Decimal attribute type that accepts fixed-point decimal values.
This maps to TypeDB's 'decimal' type, which is a fixed-point signed decimal number with 64 bits to the left of the decimal point and 19 decimal digits of precision after the point.
Range: −2^63 to 2^63 − 10^−19 (inclusive)
Example
from decimal import Decimal as DecimalType
class AccountBalance(Decimal): pass
class Price(Decimal): pass
Usage with decimal values¶
balance = AccountBalance(DecimalType("1234.567890")) price = Price(DecimalType("0.02"))
Initialize Decimal attribute with a decimal value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Decimal | str | int | float
|
The decimal value to store. Can be: - decimal.Decimal instance - str that can be parsed as decimal - int or float (will be converted to Decimal) |
required |
Example
from decimal import Decimal as DecimalType
From Decimal¶
balance = AccountBalance(DecimalType("123.45"))
From string (recommended for precision)¶
balance = AccountBalance("123.45")
From int or float (may lose precision)¶
balance = AccountBalance(123.45)