Performing basic math functions
The following table shows you the right operand for various functions you’re likely to use in Document Scripting.
|
Operand |
Name |
Example |
Result |
|---|---|---|---|
|
+ |
Addition |
2 + 2 |
4 |
|
– |
Subtraction |
2 – 2 |
0 |
|
* |
Multiplication |
2 * 3 |
6 |
|
/ |
Division |
12 / 4 |
3 |
|
** |
Power |
2**10 |
1024 |
|
% |
Mod |
12 % 9 |
3 |
|
&& |
Boolean and |
true && false |
false |
|
Boolean or | true || false | true |
|||
|
and |
Boolean and |
true and false |
false |
|
or |
Boolean or |
true or false |
true |
|
< |
Less than |
2 |
Greater than | 2 > 3 | false |
|
! |
Not |
!true |
false |
Using Document Scripting to perform basic mathematical calculations is fairly straightforward. Here are a couple of examples.
|
Input |
Output |
Notes |
|---|---|---|
|
{{ 2 + 2 }} |
4 |
All of the operands are valid here. |
|
{{ proposal_value.to_i * 10 }} |
value*10 |
Check out the methods article to find out more about using .to_i. |
|
{{ proposal_value1.to_i + proposal_value2.to_i}} |
value1 + value2 |
Check out the methods article to find out more about using .to_i. |
Convert any proposal_value to an integer prior to performing any math functions with the value.
