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

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -