Numeric Types
- class terra_sdk.core.numeric.Numeric[source]
- Input
alias of
Union
[str
,int
,float
,decimal.Decimal
,terra_sdk.core.numeric.Dec
]
- Output
alias of
Union
[int
,terra_sdk.core.numeric.Dec
]
Integers
Terra SDK uses Python’s native int
type to capture both native numbers like uint8
, as well
as Cosmos SDK’s sdk.Int
which is normally coerced into a string as it must be passed in JSON format.
The Python’s int
provides support for BigNumber implementation for artihmetic operations.
Warning
It is possible to introduce numbers larger than 256-bit precision allowed by Terra blockchain but they will result in an error when processing.
Decimals
- class terra_sdk.core.Dec(arg)[source]
BigInt-based Decimal representation with basic arithmetic operations with compatible Python numeric types (int, float, Decimal). Does not work with
NaN
,Infinity
,+0
,-0
, etc. Serializes as a string with 18 points of decimal precision.>>> Dec(5) Dec("5.0") >>> Dec("121.1232") Dec("121.1232") >>> Dec(121.1232) Dec("121.1232")
- Parameters
arg (Union[str, int, float, Decimal, Dec]) – argument to coerce into Dec
- property frac: str
Get the fractional part of the Dec value.
- Returns
fraction, as string
- Return type
str
- classmethod from_data(data)[source]
Converts Dec-formatted string into proper
Dec
object.- Return type
- ge(other)[source]
Check greater than or equal to.
- Parameters
other (Union[str, int, float, Decimal, Dec]) – compared object
- Return type
bool
- gt(other)[source]
Check greater than.
- Parameters
other (Union[str, int, float, Decimal, Dec]) – compared object
- Return type
bool
- le(other)[source]
Check less than or equal to.
- Parameters
other (Union[str, int, float, Decimal, Dec]) – compared object
- Return type
bool
- lt(other)[source]
Check less than.
- Parameters
other (Union[str, int, float, Decimal, Dec]) – compared object
- Return type
bool
- property parity: int
Get the parity of the Dec value. Returns -1 if value is below 0, and 1 otherwise.
- Returns
parity
- Return type
int
- to_data()[source]
Converts the object to its JSON-serializable Python data representation.
- Return type
str
- to_short_str()[source]
Converts to a string, but truncates all unnecessary zeros.
- Returns
string representation
- Return type
str
- property whole: str
Get the integral part of the Dec value.
- Returns
integer, as string
- Return type
str