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

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -