Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Calculate rounded percentages that always sum to 100%
ResourceFunction["RoundedPercentageShare"][data] generates a list corresponding to the percentage share of the total that each item contributes, ensuring that the result always adds up to exactly 1. |
If you simply calculate percentages and round them, values do not always add up to 1. In this case the total is 0.99:
In[1]:= | ![]() |
Out[2]= | ![]() |
In[3]:= | ![]() |
Out[3]= | ![]() |
RoundedPercentageShare always sums to 1 by allocating spare percentages to the largest contributor:
In[4]:= | ![]() |
Out[4]= | ![]() |
A second argument controls the amount of rounding:
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
RoundedPercentageShare can be applied to an Association of numerical values:
In[7]:= | ![]() |
Out[7]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License