simple way to avoid division by zero?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

simple way to avoid division by zero?

Post 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?
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: simple way to avoid division by zero?

Post 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
:)
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: simple way to avoid division by zero?

Post by Bugala »

ah. what a silly thing i didnt realise it be that simple.
Post Reply