Divide by zero is a common error in whatever language you code in. Although an error is the correct response as you can’t divide by zero, its something that we don’t want to display. One method of getting round this and displaying a nice 0 on the reportis to use a code snippet from below (depending on your language preference):
Visual Basic
1 2 3 4 5 6 7 |
Public Function Division(ByVal Dividend As Double, ByVal Divisor As Double) If IsNothing(Divisor) Or Divisor = 0 Return 0 Else Return Dividend/Divisor End If End Function |
C#
1 2 3 4 5 6 7 8 |
public object Division(double Dividend, double Divisor) { if ((Divisor == null) | Divisor == 0) { return 0; } else { return Dividend / Divisor; } } |
Leave a Comment