AX / D365FO – How to prevent the error ‘Division by zero’

If you’re gonna write code like A = B /C, you better make sure that C holds a value.
Of course you can do a check with a simple if-statement (if C then A = B/C), but there is an easier way.
You can use minOne, a method that exists in the Global class.
int a,b,c;if(b)c = a / b;elseprint " Cannot divide by zero"ORc = a /c = a / minOne(b);//it returns a itself if b is zero because minOne() returns non zero values that we passes. I//it returns a itself if b is zero because minOne() returns non zero values that we passes. If it is zero then it retuns 1
Comments
Post a Comment