Your problem comes from the fact that arguments to template functions are all evaluated before the template function itself. This means that the divide is calculated even when the test is false. Said another way, the test is an "&" and not an "&&". There is no shortcutting.
You can fix it by computing a legal divisor that is used in the test, but with the test returning the "else" value. This template is an example. I didn't use your column names, but it should be clear enough.
program:
Code:
program:
dividend = raw_field('#myint2');
divisor = ifempty(field('#myint'), 1);
format_number(
test(field('#myint'),
divide(dividend, divisor),
0),
"{0:5.1f}");
The reason I used "raw_field" is that my column was formatted with currency signs and commas, and I wanted to retrieve only the base number.