Number package guide
Use Number actions to calculate, extract parts, round, format, and compare numeric values.
Version 2.17.1. Installed versions can differ. Examples are illustrative and not tested.
Prerequisites
- Nothing to install.
- To change a variable, save the output back into it. To keep the input, save the output in another variable.
- Numbers are not exact decimals:
0.1 + 0.2is not exactly0.3, so compare with care.
Shared fields
- Fill required fields, even when they have a default. An empty optional field uses its default.
- A field used only in one mode is ignored in the other mode, but its value must still be valid.
- Choices ignore case. Save each output in a variable of the type shown.
Number: number text with a . decimal point and no thousands separator, e.g. 3.5, or a Number variable such as $amount$. Convert a String variable to Number first.
Numeric List: a List variable, e.g. $numbers$, of numbers or number text, or a JSON array such as [1,2,3]. One bad item fails the step. A String that holds JSON is not a List.
Counts: decimalPlaces, precision and numFormatDigits are whole numbers. Decimals are dropped first (2.9 gives 2).
Actions
Assign (numberAssignToNumber)
Copy a Number to the destination.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
input | Select the source number variable/ value | Numberdefault 0required | Number. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | Input value. |
Example
Set input=42; bind result to $answer$.
Expected result
$answer$ is Number 42.
Calculate Subset Sum (numberCalculateSumSubset)
Find the first group of numbers in a list that adds up to a target. Use short lists.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
input | List of numbers | Listdefault []required | Numeric List. |
sum | Target sum | Numberdefault 0optional | Target total. |
threshold | Sum deviation threshold | Numberdefault 0optional | How far the total can be from sum, e.g. 0.5. A negative value gives no match. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | List | The numbers found, in list order. Empty can mean no match, a search that stopped early, or that 0 items already match. |
Example
List $numbers$, Numbers 1, 2, 3, 4. Set inputList=$numbers$, sum=7, threshold=0; bind result to $subset$.
Expected result
$subset$ is [1,2,4], the first match found, not [3,4]. The list [2,4] gives []. For long lists the search can stop early, so [] does not prove there is no match. If sum is within threshold of 0, the result is [] at once.
Decrement (numberDecrement)
Subtract by from source.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
source | Enter number | Numberdefault 0optional | Number. |
by | Enter decrement value | Numberdefault 1optional | Amount to subtract. A negative value adds. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | source - by. |
Example
Set source=10, by=3; bind result to $total$.
Expected result
$total$ is Number 7. Omitting by uses 1.
Get decimal part (numberGetDecimalPart)
Get the part after the decimal point, with its sign.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
input | Enter number to extract fractional part from | Numberdefault 0optional | Number. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
fraction | Number | The decimal part, rounded to 12 places. |
fractions | String | The same value as number text, e.g. 0.14 or -0.14. |
Example
Set inputNumber=3.14. Bind fractionAsNumber to $fraction$ and fractionsAsString to $text$.
Expected result
$fraction$ is Number 0.14; $text$ is String 0.14. Input -3.14 gives -0.14; an integer gives 0. Very small fractions can round to zero.
Get integral part (numberGetIntegerPart)
Drop the decimals (-3.7 gives -3).
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
input | Enter number to extract integral part from | Numberdefault 0optional | Number. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
integral | Number | The whole-number part. Negatives move toward zero. |
integral | String | The same value as number text. |
Example
Set inputNumber=-3.7. Bind integralAsNumber to $integer$ and integralAsString to $text$.
Expected result
$integer$ is Number -3; $text$ is String -3. Input 3.7 gives 3; zero gives 0.
Get Maximum Number (numberGetMax)
Largest number in a list.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
numbers | List of numbers | Listdefault []required | Numeric List. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | Largest value. |
Example
List $numbers$, Numbers 1, 5, 3. Set numbers=$numbers$; bind result to $extreme$.
Expected result
$extreme$ is Number 5. It fails if the list is empty or an item is not a number.
Get Minimum Number (numberGetMin)
Smallest number in a list.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
numbers | List of numbers | Listdefault []required | Numeric List. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | Smallest value. |
Example
List $numbers$, Numbers 1, 5, 3. Set numbers=$numbers$; bind result to $extreme$.
Expected result
$extreme$ is Number 1. It fails if the list is empty or an item is not a number.
Increment (numberIncrement)
Add by to source.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
source | Enter number | Numberdefault 0optional | Number. |
by | Enter increment value | Numberdefault 1optional | Amount to add. A negative value subtracts. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | source + by. |
Example
Set source=10, by=3; bind result to $total$.
Expected result
$total$ is Number 13. Omitting by uses 1.
Random (numberRandomNumber)
Make a random whole number or decimal for test data. Do not use it for secrets.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
from | Beginning of range: | Numberdefault 0optional | Smallest value. For whole numbers, a decimal limit rounds up (1.2 gives 2). |
to | End of range: | Numberdefault 0optional | Must be larger than from. Whole numbers: up to to minus 1 (after rounding up). Decimals: below to, but rounding can reach a limit. |
is | Specify number of decimals | Booleandefault falseoptional | false gives a whole number. true gives a decimal with precision places. |
precision | Number of decimal | Numberdefault 0optional | Decimal places, 0 to 15. Other values change to the nearest limit. A 5 rounds away from zero. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | Random value. You cannot set a seed. |
Example
Set fromVal=1, toVal=10, isRequiredPrecision=false. Bind result to $sample$. For a decimal sample, use fromVal=0, toVal=1, isRequiredPrecision=true, precision=2.
Expected result
A whole number from 1 to 9. The decimal sample has at most two places, and rounding can give 1. It fails if toVal is not larger than fromVal. With decimal limits, a whole number can fall outside them, so use whole-number limits.
Round number (numberRound)
Round to a number of decimal places: nearest, up or down.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
input | Number to Round | Numberdefault 0optional | Number. |
decimal | Decimal Places | Numberdefault 0optional | 0 to 15. Above 15 uses 15. A negative value fails. |
rounding | Rounding Type | Roundingdefault normaloptional | normal: nearest, and a 5 rounds away from zero. up always rounds up, down always rounds down (for negatives too). |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | Rounded Number. End zeros are not kept; use To string to show them. |
Example
Set inputNumber=1.2341, decimalPlaces=2, roundingType=up; bind result to $rounded$.
Expected result
$rounded$ is 1.24. With input -1.2341, up gives -1.23 and down gives -1.24. normal turns -1.25 into -1.3 with one decimal place.
To string (numberToString)
Write a number as text with a set number of decimals.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
input | Enter a number | Numberdefault 0optional | Number. |
num | Enter number of digits after decimal (number format) | Numberdefault 0optional | Decimal places, 0 to 340. Other values change to the nearest limit. The text uses a . point, keeps end zeros and has no thousands separator. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | String | The text. Save it in a String variable to keep the end zeros. |
Example
Set input=35.265, numFormatDigits=3; bind result to $text$.
Expected result
$text$ is String 35.265. Input 35 with numFormatDigits=2 gives 35.00. Because numbers are not exact decimals, rounding at the last digit can surprise.
Conditions
Number condition (numberCondition)
Compare two numbers exactly, with no tolerance.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
variable | Source value | Numberdefault 0optional | Number. |
operator | Operator | Operatordefault EQoptional | Choose EQ (=), NEQ (≠), GT (>), GTE (≥), LT (<), or LTE (≤). |
value | Target value | Numberdefault 0optional | Number. |
Outputs
None. Use the condition in an If or other control step: true for a match, otherwise false.
Example
Set variable=5, operator=GT, value=3 on an If condition.
Expected result
The result is true. With operator=LTE it is false. Text that is not a number fails before the comparison.