Search…
Decimal values
The ParsiQL abstraction to work with decimal values of arbitrary precision and scale

Decimal value type

Only non-negative decimal values are supported at this moment
It is possible to represent some decimal value (i.e. 123.45678) in ParsiQL with a special (struct) type:
{
value: int256,
decimals: int256
}
For example,
...
let sampleDecimal = {value: 12345678, decimals: 5} # Represents 123.45678
...
We have introduced important (operator) functions to perform decimal value calculations.

Addition

The function add(decimalValueA, decimalValueB) takes 2 decimal values as an argument and returns their sum.

Details

Parameters
decimalValueA: {value: int256, decimals: int256}; the first decimal value
decimalValueB: {value: int256, decimals: int256}; the second decimal value
Output
{value: int256,decimals: int256}; the resulting decimal value

Example

...
let decimalValueA = {value: 5, decimals: 0} # 5
let decimalValueB = {value: 12, decimals: 1} # 1.2
let result = add(decimalValueA, decimalValueB}
# result is {value: 62, decimals: 1} (6.2)
...
If at the moment of Smart-Trigger execution the result would be equal to {value: 62, decimals: 1} which represents 6.2

Comparison

The function compare(decimalValueA, decimalValueB) takes 2 decimal values as an argument and returns
  • 1 if decimalValueA is strictly greater than decimalValueB
  • 0 if decimalValueA is equal to decimalValueB
  • -1 if decimalValueA is strictly less than decimalValueB

Details

Parameters
decimalValueA: {value: int256, decimals: int256}; the first decimal value
decimalValueB: {value: int256, decimals: int256}; the second decimal value
Output
integer; the resulting decimal value that can be either 1, 0 or -1

Example

...
let decimalValueA = {value: 5, decimals: 0} # 5
let decimalValueB = {value: 12, decimals: 1} # 1.2
let result = compare(decimalValueA, decimalValueB}
if result == 1 then
# Evaluates to "true", because result is "1", since 5 > 1.2
end
...
If at the moment of Smart-Trigger execution the result would be equal to 1, since 5 is greater than 1.2.
Last modified 1yr ago