python - How to check change between two values (in percent)? -


i have 2 values (previous , current) , want check change between them (in percent):

(current/previous)*100 

but if previous value 0 division zero, , if value not change 100%.

def get_change(current, previous)     if current == previous:         return 100.0     try:        return (abs(current - previous))/previous)*100.0     except zerodivisionerror:         return 0 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -