Perl percent calculation

If you have an array in Perl with values and want to check what the percentages of them you could use this little function:

result looks like this:

 

To make a table to compare all together:

For the format subs look at Perl format string to the same size.

result looks like this:

 

If you want some colours see this:

And now we have the result with colours:

Screenshot_percentageFor more infos about colours see at Perl Terminal Colours.

 

And now we use Perl Formater for Terminal and HTML to make this table:

Percent 20 8 7 5 3 2 1 0 -1
20 100.00% 40.00% 35.00% 25.00% 15.00% 10.00% 5.00% ?% -5.00%
8 250.00% 100.00% 87.50% 62.50% 37.50% 25.00% 12.50% ?% -12.50%
7 285.71% 114.29% 100.00% 71.43% 42.86% 28.57% 14.29% ?% -14.29%
5 400.00% 160.00% 140.00% 100.00% 60.00% 40.00% 20.00% ?% -20.00%
3 666.67% 266.67% 233.33% 166.67% 100.00% 66.67% 33.33% ?% -33.33%
2 1000.00% 400.00% 350.00% 250.00% 150.00% 100.00% 50.00% ?% -50.00%
1 2000.00% 800.00% 700.00% 500.00% 300.00% 200.00% 100.00% ?% -100.00%
0 ?% ?% ?% ?% ?% ?% ?% ?% ?%
-1 -2000.00% -800.00% -700.00% -500.00% -300.00% -200.00% -100.00% ?% 100.00%

One thought on “Perl percent calculation”

Leave a Reply

Your email address will not be published.

two × 1 =