Page 1 of 1

simple way to avoid division by zero?

Posted: Fri Feb 19, 2016 5:35 pm
by Bugala
I just got a bug in my program which happens because:
result = (a-b) / c

in some cases a-b might result in 0, and hence it is trying to:
0 / c

I can, and will make necessary cautions to avoid this happening, but does there happen to be some simple way, perhaps even a command that would result in 0 when division by zero happens?

Re: simple way to avoid division by zero?

Posted: Fri Feb 19, 2016 11:42 pm
by airsoftsoftwair
Simple way to avoid division by zero? What about

Code: Select all

If c <> 0 Then result = (a-b) / c Else result = 0
:)

Re: simple way to avoid division by zero?

Posted: Sat Feb 20, 2016 8:22 am
by Bugala
ah. what a silly thing i didnt realise it be that simple.