dkim18
asked on
Double.parseDouble behavior
this is something I don't get...
I declared like this:
minXSinTField = new JTextField("0.0", 4);
and then I am using this func to test input validation.
isValidInput(minXSinTField );
This is the func.
public boolean isValidInput(JTextField tf) {
boolean result = true;
try {
Double.parseDouble(tf.getT ext());
result = true;
System.out.println("in try section");
System.out.println(result) ;
}
catch (NumberFormatException ex) {
result = false;
System.out.println("in catch section");
System.out.println(result) ;
}
System.out.println("before return;");
System.out.println(result) ;
return result;
}
Now, when I enter any string this func returns true.
From other pane's textfields, when I enter string this func returns false.
I don't know why...
I declared like this:
minXSinTField = new JTextField("0.0", 4);
and then I am using this func to test input validation.
isValidInput(minXSinTField
This is the func.
public boolean isValidInput(JTextField tf) {
boolean result = true;
try {
Double.parseDouble(tf.getT
result = true;
System.out.println("in try section");
System.out.println(result)
}
catch (NumberFormatException ex) {
result = false;
System.out.println("in catch section");
System.out.println(result)
}
System.out.println("before
System.out.println(result)
return result;
}
Now, when I enter any string this func returns true.
From other pane's textfields, when I enter string this func returns false.
I don't know why...
Please post input
Hi dkim18,
Try this:
public boolean isValidInput(JTextField tf) {
try {
Double.parseDouble(tf.getT ext());
return true;
}
catch (Exception ex) {
return false;
}
}
Try this:
public boolean isValidInput(JTextField tf) {
try {
Double.parseDouble(tf.getT
return true;
}
catch (Exception ex) {
return false;
}
}
ASKER
Webstorm,
when I entered string, it still returns true...
CHEJ,
minXSinTField = new JTextField("0.0", 4);
when I entered string, it still returns true...
CHEJ,
minXSinTField = new JTextField("0.0", 4);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
when I enter string "input"
the outcome was:
Input is (0.0)
the outcome was:
Input is (0.0)
ASKER
I found error.
I am sharing same private members for two panes...
that was why...
thanks anyway,
I am sharing same private members for two panes...
that was why...
thanks anyway,
:-)