Airkit supports the standard subtraction operator -
. It is used to subtract Number values from other Numbers and Currency values from other Currencies.
Example
Subtracting Numbers
The following example shows how the subtraction operator is used to subtract the Number 2 from the Number 3. Note that it returns a another Number: 1, 2 less than 3:
3 - 2 -> 1
Subtracting Currency
The subtraction operator can be used to subtract Currencies provided the Currency values have the same currency code. For instance, say you have two Currency values, currency_1
and currency_2
, defined as follows:
currency_1 -> {
"amount": 3000,
"code": "USD",
"precision": 2
}
currency_2 -> {
"amount": 1000,
"code": "USD",
"precision": 2
}
currency_1
and currency_2
both represent money in US dollars, so one can be subtracted by the other using the subtraction operator:
currency_1 - currency_2 -> {
"amount": 2000,
"code": "USD",
"precision": 2
}
Airscript supports negative Currency values, so it is also possible to use the subtraction operator to subtract currency_1
from currency_2
, as follows. Note that the resulting Currency has a negative amount value:
currency_2 - currency_1 -> {
"amount": -2000,
"code": "USD",
"precision": 2
}
Currency values cannot be subtracted if they do not have matching currency codes. For example, say there is a third Currency value, currency_3
, in Euros rather than dollars, defined as follows:
currency_3 -> {
"amount": 2000,
"code": "EURO",
"precision": 2
}
Attempting to use the subtraction operator to subtract currency_3
from currency_1
will result in an error, because the subtraction operator cannot subtract euros from US dollars:
currency_1 + currency_3 -> ERROR