percentage
Calculates a percentage value — (base/whole) * 100.
Parameters
BASE VALUE (number)
The base value.
WHOLE VALUE (number)
The whole value.
DECIMAL PLACES (number or string)
Optional. The number of decimal places for the result.
You can set the default for this parameter in your project settings. If set to useNumberFormat, the number of decimal places is taken from your project's default number format pattern.
Default: useNumberFormat
STRIP TRAILING ZEROS (Boolean or string)
Optional. Whether to strip trailing zeros from the result (true) or leave them in place (false).
You can set the default for this parameter in your project settings. If set to useNumberFormat, the decision to strip or retain trailing zeros is taken from your project's default number format pattern.
Default: useNumberFormat
Important
The default values above are the system defaults. You can change these defaults in your project's Settings view. See Settings > Number and Currency for guidance.
Examples
Assume the settings in Settings > Number and Currency are:
Setting | Value |
---|---|
NUMBER FORMAT |
|
DECIMAL PLACES FOR PERCENTAGE |
|
STRIP TRAILING ZEROS FOR PERCENTAGE |
|
If the optional parameters are unspecified, the project settings apply.
ATL in Script | Result |
---|---|
| 4 |
| 1.5 |
| 16.67 |
Use the third parameter to specify the number of decimal places.
ATL in Script | Result |
---|---|
| 17 |
| 16.6667 |
Note
Half-up rounding applies automatically.
Set the fourth parameter to false to include trailing zeros.
ATL in Script | Result |
---|---|
| 4 |
| 4.000 |
Using percentage with table data
Assume a "Describe the Table" project with this data:
Branch | Orders | salesRev | COGS | otherRev | otherExp | netProfit | |
---|---|---|---|---|---|---|---|
Row 1 | Aberdeen | 15 | 14,000 | 8,000 | 2,000 | 1,500 | 6,500 |
Row 2 | Edinburgh | 35 | 33,000 | 19,000 | 2,000 | 3,500 | 12,500 |
Row 3 | Inverness | 18 | 16,000 | 8,250 | 1,200 | 1,500 | 7,450 |
Row 4 | Glasgow | 35 | 32,500 | 17,750 | 1,250 | 1,700 | 14,300 |
Here's how you might use percentage
with this data:
[[
totalSalesRev = totalVal(salesRev)
totalOtherRev = totalVal(otherRev)
allRev = totalVal(totalSalesRev, totalOtherRev)
salesRevAsPercentage = percentage(totalSalesRev, allRev)
joinStrings('Sales revenue accounts for ', salesRevAsPercentage, '% of all revenue')
]]
The output text:
Sales revenue accounts for 93.7% of all revenue.