Solved

Double.parseDouble behavior

Posted on 2004-04-02
7
392 Views
Last Modified: 2010-03-31
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.getText());
      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...
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10741405
Please post input
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10741411
Hi dkim18,


Try this:

  public boolean isValidInput(JTextField tf) {
    try {
      Double.parseDouble(tf.getText());
      return true;
    }
    catch (Exception ex) {
      return false;
    }
  }
0
 

Author Comment

by:dkim18
ID: 10741772
Webstorm,

when I entered string, it still returns true...

CHEJ,

minXSinTField = new JTextField("0.0", 4);

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 13

Accepted Solution

by:
Webstorm earned 125 total points
ID: 10741858
Display the value returned by getText() :

  public boolean isValidInput(JTextField tf) {
    try {
      System.out.println("Input is ("+tf.getText()+")");
      Double.parseDouble(tf.getText());
      return true;
    }
    catch (Exception ex) {
      return false;
    }
  }
0
 

Author Comment

by:dkim18
ID: 10741929
when I enter string "input"
the outcome was:

Input is (0.0)
0
 

Author Comment

by:dkim18
ID: 10741950
I found error.
I am sharing same private members for two panes...
that was why...

thanks anyway,
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10742041
:-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question