Yes, this comes under the heading of trapping exceptions, in this case the divide-by-zero exception.
You would have the same problem if one month was 0 and the next anything. For example 0 to 10: (10-0)/0
It is because you are asking "what is the relative change since last month" - how do you relate to a zero month?
So, you must have an "if (A == 0) { PctDiff=0 } else { PctDiff=((B-A)/A)*100 }" kind of code. (I just made PctDiff=0, but even better would be to print out an "N/A" or something to show that you know it is not possible to calculate the %)
BTW, what language are you writing it in?