...

View Full Version : Finding a Divide By Zero Error with Doubles



turtlegk33
02-08-2008, 03:55 AM
I am trying to create a calculator and I cannot figure out how to bring up a divide by zero error using doubles.

else if(temp == '/'){
String test = Double.toString(var2);
char one = test.charAt(0);
if(one == '0'){
System.out.print("aaa");
text.setText("Cannot Divide By Zero Err");
}else
var2 = var1 / var2;


The system.out is just a test to see if it goes into the if statement and it does.

shyam
02-08-2008, 07:07 AM
if ( Double.parseDouble(divisor.getText()) == 0 ) {
// divisor is zero !!
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum