Signed Integers
For smaller numbers, either form of integers can be used, but the Signed Integer sub-type is easier to use from a scripting point of view, so it is probably the sub-type of choice. In order to select the sub-type, select the attribute in the BOM class, and look at the Advanced Properties sheet:
In scripting, to work out the average weight of a team member, you can do the following:
var totalKgs = 0; var teamSize = 0; for (var iterator = team.members.listIterator(); iterator.hasNext(); ) { var member = iterator.next(); totalKgs = totalKgs + member.weightKgs; teamSize = teamSize + 1; } if (teamSize > 0) { team.averageWeight = totalKgs / teamSize; } else { team.averageWeight = 0; } |
Note that the two lines in the loop that update the running totals can be shortened to:
using the arithmetic abbreviations that can be used in scripting.
When dividing, do not divide by 0. The code above checks for this special case. The operators for comparing signed integers are:
Operator | Description | Example | Result |
---|---|---|---|
== | Equals | 1 == 2 12 == 12 |
false true |
!= | Not Equals | 1 == 2 12 == 12 |
true false |
< | Less than | 1 < 2 12 < 12 21 < 20 |
true false false |
<= | Less than or equals | 1 <= 2 12 <= 12 21 <= 20 |
true true false |
>= | Greater than or equals | 1 >= 2 12 >= 12 21 >= 20 |
false true true |
> | Greater than | 1 > 2 12 > 12 21 > 20 |
false false true |
See Working with Fixed Length Integers (BigInteger) for more information.