I
I
IvanOne2018-11-12 13:05:06
Python
IvanOne, 2018-11-12 13:05:06

How to round percentages correctly?

There is such a set of data that add up to 100% {'key_1': 10.55, 'key_2': 30.90, 'key_3': 58.55}. What methods are there to round numbers to integers but at the same time to get 100 as a result? Is there a package or something from the python standard library?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Tsvetkov, 2018-11-12
@IvanOne

There is a so-called "accounting" rounding to the sum. For example, I will not take a percentage, how to divide 100 rubles between three employees: each receives 1/3 of the amount, the last balance is (33.33 + 33.33 + 33.34).
Additionally: not to be confused with "accounting" (or "banking") rounding to the nearest even number (the processor has a special register for switching rounding from mathematical to accounting).
Rounding Riddles .

G
Griboks, 2018-11-12
@Griboks

Always after rounding the error will be 1%. So write - (59 + -1)%.

V
Vladimir Romashko, 2018-11-13
@readmap

Just like any other mathematical quantities.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question