• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

general

Hi

In a scenario where there is a divison
and the divisor is zero
i shd get a result directly as zero
ex
a = 1
b = 0
c = a/b
in above case the error will be divisor zero
so i shd get output directly as '0'

help me
0
iamtechnical
Asked:
iamtechnical
  • 2
  • 2
1 Solution
 
gplanaCommented:
I'm not sure if I understood your question, but to avoid the divide by zero error you should do something like this:

a = 1
b = 0

if b=0 then
   c = 0
else
   c = a/b
end if

Please note that the notation used could differ depending on the language, so if for example you want to write this in C or Java, you should write:

a = 1;
b = 0;

if (b==0) {
   c = 0;
}
else {
   c = a/b;
}

Hope it helps.
0
 
iamtechnicalAuthor Commented:
yup

u got it write

but i was confused

actually i used sql

so here it is

decode(b,0,0,a/b) as c

0
 
iamtechnicalAuthor Commented:
gud and fast response
0
 
gplanaCommented:
Excellent. Thank you.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now