What if Textfield t1 is blank?? num1=Double.parseDouble(t1.getText());

Hi there
Im coding a simple calculator with 2 Textfield for entering two numbers. If one of Textfields is blank and an operation button (+,-,*,/) is clciked, I want the 3rd Textfield t3 to read "ERROR".
From the code below, what is num1 if t1 is blank. Or could you tell me how to go about this if statement.
if (ae.getSource()==multi){
               num1=Double.parseDouble(t1.getText());
               num2=Double.parseDouble(t2.getText());
               res=num1*num2;
               t3.setText(""+res);
cheers
SERGIO

I look forward to you figuring this out yourself.
1. What does getText() return when then JTextField is empty?
2. What happens when you pass that to parseDouble?
3. Should you even bother passing that to parseDouble?

Similar Messages

  • Variants of Double.parseDouble

    I have an applet that runs perfectly on appletviewer but screws up when viewed through my web browser. It doesn't parse the string( number ) found in my textfield( input ). I did it like this: "x = Double.parseDouble( input.getText() );". what is the syntax that i should follow to conform with those that my browser could support? Probably an older one. My browser is IE 4 or 5... Thanks!

    Sun must have been struggling for a bit 'cos it wasn't until JDK1.2 that they introduced Double.parseDouble, even though Integer.parseInt has been there since the dawn of time itself.
    And since Microsoft stopped supported Java around JDK1.1.6 you'll probably find that your Applet is complaining that there's no such method (have a look in the Java Console in IE to see what it's got to say for itself).
    There are various things you could do:
    1) install the Java Plug-in to bring your JVM into this century
    2) see if DecimalFormat is supported by your runtime (can't find when it was introduced in the Javadocs - sorry)
    3) write your own simple double-parsing routine
    Personally I'd opt for 1. I'd be tempted to do option 2 as well but it's hardly necessary!
    Hope this helps.

  • IPhoto Slow, Blank thumbs, double import, did I mention S L O W

    iPhoto Slow, Blank thumbs, double import, did I mention S L O W? iMac G5, 768 Ram, I loaded and EDITED 500 photos, went to export. Found thousands of images in machine I never loaded. Attempted to export some photos to flickr (before finding they had a fix). Nothing.
    So I did, what any MS user would do, I reinstalled iPhoto. Now there are 500 empty frames, some with ghosts, and 2 sets of newly imported fotos. Tried to do some deleting, but no benefit.
    Any suggestions?

    Sorry to hear you're having problems like this - I have 768 MB of RAM on a G4, and I have seen no slowdown with 13,000+ photos.
    Could you be more specific with how you arrived at the problem? Here's some questions that come to mind:
    - What kind of images? JPG? RAW? approximately what size and resolution?
    - Blank thumbs are usually a result of things being moved around in the iPhoto library, and the iphoto database loses track of the paths. The golden rule is, never mess with the organization of your iPhoto library from within the Finder.
    - Usually if an application is that slow it is running into problems, so if you launch Console, and then iPhoto, you may see new messages that may indicate a problem.
    - The thousands of images in the machine, that you never loaded, what are they? Are they images that were in your Pictures folder? Did someone else use the computer?
    - What do you mean by double import? If you leave your camera or card reader connected, you will be shown the screen where iPhoto is ready to import. If you choose to import again, you could double-import.
    - If iPhoto finds photos at the root level of its iPhoto Library folder, it may try to import them. If interrupted or if the application is forced to abandon the import, it may try again on relaunch.
    - How did the export to flickr fail? Was it with the blank thumbnails selected?
    Maybe information that could answer the above questions, could help me or someone on the discussion board help you figure out what's going on.

  • What 's the difference between quote ' and double quote "?

    what's the difference between quote' and double quote "?
    when we use each one?
    Exemple of use of each case?

    'c' is a char, ie. a primitive type representing a single character
    "c" is an instance of the String class length 1.

  • Double.parseDouble help?

    I have this String Number 20.000. When I do a parseDouble I get 20.0 which is right.
    public class qwerty {
         public static void main(String[] args) {
              String num = "20.000";
              System.out.println(Double.parseDouble(num));
    But is there a way to preserve the zeroes and it prints 20.000 itself after parse Double?

    But is there a way to preserve the zeroes and it prints 20.000 itself after parse Double?Not directly. Doubles (and doubles, and all other Number subclasses and number primitives) store only information about the value of the number, not how it is to be displayed.
    As mentioned, you'll need to use formatting provided either by a DecimalFormat object or a printf() function. To do what you're asking, you'd need to somehow parse the input string to determine the required format, and store that information separately (e.g. in a String or a DecimalFormat object), then use that whenever you want to display the number. Check out the documentation for DecimalFormat and PrintStream.printf().
    Regex would probably be helpful if you decide to go that route.

  • Double.parseDouble

    the user enters a premium amount and then I want to use that amount in a calcuation; can't I parseDouble it like this? apparently not, because when I try to multiply, I get an error "the operator * is undefined for argument type(s) double, String. I have done this in the past, what is wrong?
    String pAmount = JOptionPane.showInputDialog("Enter the premium amount:");
    double num = EndCancelDiffCounter;
                   double denom = counter;
                   double result = num/denom;
                   Double.parseDouble(pAmount);
                   double refund = result * pAmount;

    parseDouble returns a double, it does not change the
    String given froma String to a double. You need to
    store that result (return value) in a new double
    variable and perform your calculation with that.
    Edit: Man I'm slow. (I had to check that
    parseDouble returned a double and not a Double. I
    wasn't 100% sure, as I'm a little daft this morning.)I see, thank you

  • Issue with Double.parseDouble

    ok i dono whats going on here im writing a console based bank management program and when converting a input srting from console.readline to Double.parseDouble it says the method parseDouble cannot be found, im using the latest jvm whats going on! help!

    my bad i ment latest jdk not thinking tonight! heres the error:
    D:\My Documents\Java\Bank Acount\AccountDriver.java:59: Method parseDouble(java.lang.String) not found in class java.lang.Double.
                             newAcc = Double.parseDouble (input);
                             ^
    1 error

  • Double.parseDouble returning 2.0E7

    Hi,
    I have a piece of code (snippet below)
    double aggrAmount=0.0;
    Tag t;
    aggrAmount=Double.parseDouble(t.getValue().substring(t.getValue().lastIndexOf("/")+1, t.getValue().length()-1));
    where t="AGGR//FAMT/20000000,"
    when i check aggrAmount the value is 2.0E7. How can i get the value as it is?
    PLs help...
    THanks for your time and advice

    when i check aggrAmount the value is 2.0E7. How can i get the value as it is?There's some confusion here between the value (a double value of twenty million), and the String you use to check it ("2.0E7"). They are different things.
    If you want to see or use the value in a string without the exponent business, use String.format() or DecimalFormat. Note that the value remains what it is (twenty million); numbers don't have a format.
    If you want the last part "as it is" ie as a String use String's lastIndexOf() and substring() methods and make value a String.

  • Double.parseDouble(String) - problems when string is in scientific notation

    Hello guys,
    I'm doing some numerical calculations and I wonder whether it is possible for Double.parseDouble(String) to parse string in the scientific notation i.e. 1.0824234234E-10. Is it the notation itself causing the exception : NumberFormatException or the number is just too big/small and double can't hold it ?
    If it's just the notation how can I fix it ?
    Regards

    i'm not quite sure whether double odoes not allow it.
    perhaps consider the api Double.valueOf() and the testing code provided; reproduced below:To avoid calling this method on a invalid string and having a NumberFormatException be thrown, the regular expression below can be used to screen the input string:
            final String Digits     = "(\\p{Digit}+)";
      final String HexDigits  = "(\\p{XDigit}+)";
            // an exponent is 'e' or 'E' followed by an optionally
            // signed decimal integer.
            final String Exp        = "[eE][+-]?"+Digits;
            final String fpRegex    =
                ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
                 "[+-]?(" + // Optional sign character
                 "NaN|" +           // "NaN" string
                 "Infinity|" +      // "Infinity" string
                 // A decimal floating-point string representing a finite positive
                 // number without a leading sign has at most five basic pieces:
                 // Digits . Digits ExponentPart FloatTypeSuffix
                 // Since this method allows integer-only strings as input
                 // in addition to strings of floating-point literals, the
                 // two sub-patterns below are simplifications of the grammar
                 // productions from the Java Language Specification, 2nd
                 // edition, section 3.10.2.
                 // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
                 "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
                 // . Digits ExponentPart_opt FloatTypeSuffix_opt
                 "(\\.("+Digits+")("+Exp+")?)|"+
           // Hexadecimal strings
           "((" +
            // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
            "(0[xX]" + HexDigits + "(\\.)?)|" +
            // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
            "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
            ")[pP][+-]?" + Digits + "))" +
                 "[fFdD]?))" +
                 "[\\x00-\\x20]*");// Optional trailing "whitespace"
      if (Pattern.matches(fpRegex, myString))
                Double.valueOf(myString); // Will not throw NumberFormatException
            else {
                // Perform suitable alternative action
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Double.html

  • Double.parseDouble(String) : Problem to parse large String

    Hello,
    I need to convert A String to a Double in my application without rounding of digits.
    I have used the Double.parseDouble(String) method.
    The maximum string length can be 17 including dot(.)
    So if my String is (of length 17)
    Eg.
    S= �9999999999.999999� then I am getting the double value as
    d= 9999999999.999998(compare the last digit)
    If s = �9999999999.111111� then d = 9999999999.111110
    If s = �9999999999.555555� then d = 9999999999.555555 (result that I want)
    If s = �9999999999.666666� then d = 9999999999.666666 (result that I want)
    If s = �9999999999.777777� then d = 9999999999.777777 (result that I want)
    If s = �9999999999.888888� then d = 9999999999.888887
    If s = �9999999999.999999� then d = 9999999999.999998
    If s = �9123456789.123456� then d = 9123456789.123456
    But string length up to 16 is giving me the accurate result
    So any body can explain me that why it is happening? And how can i get the accurate result.
    Thanks in advanced.

    Hi,
    Thank You for your suggestion. By which i can store
    the big double number in Data base , but at some
    point i require to parse a double value from a Double
    reference.In that case if the Decimal value length
    => 16 then it the last digit changes or rounds.
    coverting 9999999999.999999 Decimal value to double
    value. It gives me 9999999999.999998 and
    9999999999.9999999 gives me the 10000000000.0000000.
    but the Double value 999999999.999999 is ok
    and 999999999.99999999 rounds.Err, is there a follow up question in there?

  • Double.parseDouble() is not Locale specific, how do I get round this?

    I am parsing Strings into doubles using
    String myNumber = "12,34";
    double d = Double.parseDouble( myNumber );The problem is that my number is of French style (it has commas instead of fullstops for the decimal points)
    The default Locale is English, so I get NumberFormat problems when parsing. (I can understand this)
    I even get NumberFormat problems when I do this:
    Locale.setDefault(Locale.FRENCH);
    double d = Double.parseDouble( myNumber );Which I think is really strange. I guess the Locale of Double is set at a certain time and not reset.
    OR maybe Double.parseDouble( <STRING> ); is not Locale specific?
    Where is my understanding wrong?

    Do you know if DecimalFormat reflects the default Locale if the default Locale changes?
    Or will I have to make a new DecimalFormat whenever it changes?As Locale is invariant, a DecimalFormat instance (as well a any object with a reference to the default Locale) cannot reflect the default Locale changes.
    But each time you create a new instance of DecimalFormat without specifying the Locale, it will get up-to-date Locale.
    However, you might prefer setting the locale explicitely (instead of changing the default one.)
    Note that Double valueOf() or parseDouble() methods are not related to default Locale, they use a fixed format.

  • Double.parseDouble lost of precision!

    Hello,
    I have a small problem regarding convertion from string to double.
    double dTotal;
    dTotal = Double.parseDouble("10.01") + Double.parseDouble("0.12");
    Can someone explain me why my result is dTotal = 10.12999999999999 ?
    Thanks in advance.
    Remi.

    and read
    http://docs.sun.com/source/806-3568/ncg_goldberg.html
    This, too:http://java.sun.com/developer/JDCTechTips/2003/tt0204.html#2

  • Problem on Double.parseDouble

    Double.parseDouble(InputString); was error on my NetBeans 6.8 how to fixed it? I've tried to reinstall but still the same

    Make sure you are using CLDC 1.1. Double is not included in CLDC 1.0.
    Erik Wetterberg

  • Does browser support Double.parseDouble()???

    hi,
    i have used Double.parseDouble() method in my program. After i run that program in browser, it shows error "Double.parseDouble() method not found". Doesnt browser support Double.parseDouble()??? Can anybody tell me how to solve this error?? (i have also tried Float.parseFloat(),but same error occurs) Please help me.
    Thanks in advance,
    Kalpana.

    Newer non-Microsoft browsers such as Netscape 6 and Opera 5 support JDK 1.3. I think IE 5.1 for Mac OS X will use the JDK 1.3 installed on the computer, also. It's only older browsers and IE for Windows and Mac OS 9.1 and before that do not support JDK 1.3. Unfortunately, that's 90% of all browsers! :-(

  • SOLVED What benifits are there to Blank Padding values in a DB?

    I was witting some SQL last week and got really frustrated when I couldn't figure out why my joins were not working from on DB to another. I eventually found that there where blanks tagged on to the end of all of the values of one of the columns I was joining. I knew right off how to take care of the problem (RTRIM), but I found myself wonder today why this practice exists. Google couldn't really answer my question so I turn to you guys.
    What is the purpose or reason behind blank padding values in a DB?
    My assumption of course is that the creator of the DB I'm working with actually did have a purpose, but I was informed by my coworker that they didn't deserve that level of credit. LOL. Still, if the feature or option exists there must be a reason.
    Thanks for your help,
    David

    Can't imagine why they are right padded, though. Left
    padded could be explained.My bad, for a moment I thougth CHARs got left padded, when they are in fact right padded.
    create table t (c char(3));
    insert into t values ('X');
    commit;
    select dump(c) from t;
    DUMP(C)                                                                        
    Typ=96 Len=3: 88,32,32                                                         
    1 row selected.Regards
    Peter, now answering himself

Maybe you are looking for

  • Is There A Cheap Or Even Free Way Of Recovering Deleted Files?

    I tend to be a bit quick at trashing things and emptying the trash! Sometimes I wish I hadn't - but so far I have never had a catastrophic loss. I know there are companies, who, for a small fortune can recover data, but is there any cheap DIY method

  • How do I continue to download my movie ?

    I was downloading a movie onto my ipod touch from itunes on my ipod and my ipod went dead and so I let it charge and it came back and then i try to resume my download process and it says: download error .....HELP!

  • ASA 5510 8.2(1) Using hostnames in access-lists?

    I need to allow a specifc hostname through my firewall. I found this article: https://supportforums.cisco.com/docs/DOC-17014 But it's only for 8.4 updated ASA's and above. Doing more research, I found this article: http://www.handbook.dk/block-domain

  • When I use Skype Adobe crashes.

    This has been happening for the last few days. I sign into Skype then after about a minute or as soon as someone tries to call me on there Skype does not allow me to neither decline or accept the call and then freezes saying at the top that its not r

  • Compressing dialogue tracks on FCPX

    We are completing our first major project on FCPX. In FCP 7, we'd export a combined .wav tracks capturing all the dialogue on the episode. We'd exclude music, FX, etc. We'd them round trip it through STP and apply compression. IS there a streamlined