This article demonstrates the behavior of integer or float data when arithmetic operators are used in the formula mode.
What you'll need:
Skill level: Intermediate
Time required: 3 minutes
- Skills of arithmetic operators
Quickwork supports a variety of arithmetic formulas. Formulas are whitelisted Ruby methods, and therefore not all Ruby methods are supported. Syntax and functionality for these formulas are generally unchanged. Take note that most formulas will return an error and stop the job if it tries to operate on nulls (expressed as nil in Ruby).
Arithmetic operations
In the cases of arithmetic operations, the values in integer types or decimal (float) types are important. Formulas will always stick to the types given as input, and the returned result will be of the most precise type.
For example:
- If integer values are provided, an integer value will be returned.
- If float values are provided, a float value will be returned.
- If both float and integer values are provided, a float value will be returned as that is more precise.
The add (+) operator
This operator allows the addition of operands present on both sides:
Example | Result | Type |
4 + 7 | 11 | Integer |
"John"+"Doe" | JohnDoe | String |
13.5+2 | 15.5 | Float |
The subtract (-) operator
This operator subtracts the right-hand operand from the left-hand operand:
Example | Result | Type |
4 - 7 | -3 | Integer |
"JOHN"-"HN" | null | String |
13.5-2 | 11.5 | Float |
The multiply (*) operator
This operator multiplies the operands on either side:
Example | Result | Type |
4*7 | 28 | Integer |
-32*28 | -896 | Integer |
-23.67*22.4 | -530.208 | Float |
The divide (/) operator
Divides left-hand operand by right-hand operand:
Example | Result | Type |
4/7 | 0.5714285714285714 | Integer |
-32/28 | -1.1428571428571428 | Integer |
23.67/22.4 | 1.0566964285714286 | Float |
You can refer to the complete Ruby documentation for integers here as well as the Ruby documentation for float (decimals) here.
Comments
0 comments
Please sign in to leave a comment.