Difference between revisions of "Complex formulas"
Jump to navigation
Jump to search
old>Admin |
|||
(13 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Calculated formulas syntax follows is compliant with JavaScript syntax. | |||
==== Common operators ==== | ==== Common operators ==== | ||
Line 6: | Line 7: | ||
* Multiply: * | * Multiply: * | ||
* Modulus: % | * Modulus: % | ||
* Precedence: ( ... ) | |||
==== Mathematical functions ==== | ==== Mathematical functions ==== | ||
* Minimum | * Absolute: abs | ||
* Maximum | * Minimum: max | ||
* Maximum: min | |||
* Power: pow | |||
* Square root: sqrt | |||
* Logarithms: log log10 exp | |||
* Rounding: ceil floor round | |||
==== Mathematical constants ==== | |||
* Pi: pi | |||
* E: e | |||
==== Support for statements ==== | ==== Support for statements ==== | ||
This feature is enabled starting from version 2366. | |||
===== IF statement ===== | ===== IF statement ===== | ||
* Test | Syntax used matches JavaScript inline IF statments. | ||
** Equal: = | |||
** Unequal: != | To make the statement work make sure to add a space: before <code>)</code>, after <code>(</code>, before and after <code>?</code> and <code>:</code>.<syntaxhighlight lang="js"> | ||
** Greater: > (>=) | ( Value1 Operator Value2 ? ValueIfTrue : ValueIfFalse ) | ||
** Lesser: < (<=) | </syntaxhighlight> | ||
* | * Test | ||
** | ** First value or expression | ||
** | ** Operator | ||
*** Equal: = | |||
*** Unequal: != | |||
*** Greater: > (>=) | |||
*** Lesser: < (<=) | |||
** Second value or expression | |||
* Result | |||
** TRUE value or expression | |||
** FALSE value or expression | |||
===== Examples ===== | ===== Examples ===== | ||
Script code | Script code / specification | ||
var result; | |||
if ( [NUMBER1] > [NUMBER2] ) { | |||
result = [NUMBER1] * 11; | |||
} | |||
else { | |||
result = [NUMBER3]; | |||
} | |||
return result; | |||
Expression | Expression to use in formula | ||
( [NUMBER1] > [NUMBER2] ? [NUMBER1] * 11 : [NUMBER3] ) |
Latest revision as of 09:43, 19 August 2022
Calculated formulas syntax follows is compliant with JavaScript syntax.
Common operators
- Add: +
- Subtract: -
- Division: /
- Multiply: *
- Modulus: %
- Precedence: ( ... )
Mathematical functions
- Absolute: abs
- Minimum: max
- Maximum: min
- Power: pow
- Square root: sqrt
- Logarithms: log log10 exp
- Rounding: ceil floor round
Mathematical constants
- Pi: pi
- E: e
Support for statements
This feature is enabled starting from version 2366.
IF statement
Syntax used matches JavaScript inline IF statments.
To make the statement work make sure to add a space: before )
, after (
, before and after ?
and :
.
( Value1 Operator Value2 ? ValueIfTrue : ValueIfFalse )
- Test
- First value or expression
- Operator
- Equal: =
- Unequal: !=
- Greater: > (>=)
- Lesser: < (<=)
- Second value or expression
- Result
- TRUE value or expression
- FALSE value or expression
Examples
Script code / specification
var result; if ( [NUMBER1] > [NUMBER2] ) { result = [NUMBER1] * 11; } else { result = [NUMBER3]; } return result;
Expression to use in formula
( [NUMBER1] > [NUMBER2] ? [NUMBER1] * 11 : [NUMBER3] )