Python: Calculate percentages

To convert variables into percentages in Python, you need to ensure that it is calculating with floats (or doubles or whatever it is its using)

percentage = (count / total) * 100

Will keep returning 0.

percentage = (1.0 * count / total) * 100

This is the right way of doing it and works fine.

If anyone knows a better way of doing it, let me know!

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog