Error with rule of three in php

I have a simple 3 rule whose number comes from a list.

This is the error

Warning: Division by zero in /public_html/index.php on line 179

$ a = $ cont-> rowCount (); // Total activities
$ b = $ contc-> rowCount (); // Resulting activities
$ result = $ b * 100 / $ a;

The variable $ b for the moment has the brings the value 0 since there is no determined activity and try to do the following:

if ($ b =! 0) {
    $ result = $ b * 100 / $ a;
}

but the error is the same, I do not know how to solve it.