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:
1
{
2
value: int256,
3
decimals: int256
4
}
Copied!
For example,
1
...
2
let sampleDecimal = {value: 12345678, decimals: 5} # Represents 123.45678
3
...
Copied!
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

1
...
2
let decimalValueA = {value: 5, decimals: 0} # 5
3
let decimalValueB = {value: 12, decimals: 1} # 1.2
4
​
5
let result = add(decimalValueA, decimalValueB}
6
​
7
# result is {value: 62, decimals: 1} (6.2)
8
...
9
​
Copied!
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

1
...
2
let decimalValueA = {value: 5, decimals: 0} # 5
3
let decimalValueB = {value: 12, decimals: 1} # 1.2
4
​
5
let result = compare(decimalValueA, decimalValueB}
6
​
7
if result == 1 then
8
# Evaluates to "true", because result is "1", since 5 > 1.2
9
end
10
​
11
...
12
​
Copied!
If at the moment of Smart-Trigger execution the result would be equal to 1, since 5 is greater than 1.2.
Last modified 9mo ago