Can't get it to round to 2 decimals, using DecimalFormat, please proof read

Why won't this output #.##? No matter how I change them it still gives me exact answers.
   import javax.swing.*;
   import java.awt.*;
   import java.util.*;
   import java.text.DecimalFormat;
    public class Calculator{
       public static void main (String[] args){
      //Ask for input
         String inputString = JOptionPane.showInputDialog("Input your desired calculation, separating numbers and operation with spaces.(+-/*%)");
      //split input to make switch function
         String[] result = inputString.split("\\s");
      /*I Put both of these in here, but stuck with the Double,
      I think thats the better fit*/
      //float n1 = Float.parseFloat(result[0]);
      //float n2 = Float.parseFloat(result[2]);
         double n1 = Double.parseDouble(result[0]);
         double n2 = Double.parseDouble(result[2]);
         char c = result [1].charAt(0);
         if((c == '+')  || (c == '/') || (c == '*') || (c == '%') || (c == '-'))
         DecimalFormat df = new DecimalFormat("#.##"); 
         //switch function to cover the 5 functions, and divide by zero message
            switch(c)
               case '+':
                  double answer = n1 + n2;           
                  df.format(answer);
                  JOptionPane.showMessageDialog(null, inputString + " = " + (answer));
                  break;
               case '-':
                  //DecimalFormat df = new DecimalFormat("#.#");            
                  double answer2 = n1 + -n2;           
                  df.format(answer2);
                  JOptionPane.showMessageDialog(null, inputString + " = " + (answer2));
                  break;
               case '/':
                  if(n2 == 0)
                     JOptionPane.showMessageDialog(null, "You know that's a no no!");
                  else
                     //DecimalFormat df = new DecimalFormat("#.#");            
                     double answer3 = n1 / n2;           
                     df.format(answer3);             
                     JOptionPane.showMessageDialog(null, inputString + " = " + (answer3));
                  break;
               case '*':
                  //DecimalFormat df = new DecimalFormat("#.#");            
                  double answer4 = n1 * n2;           
                  df.format(answer4);           
                  JOptionPane.showMessageDialog(null, inputString + " = " + (answer4));
                  break;
               case '%':
                  //DecimalFormat df = new DecimalFormat("#.#");            
                  double answer5 = n1 % n2;           
                  df.format(answer5);         
                  JOptionPane.showMessageDialog(null, inputString + " = " + (answer5));
                  break;
         else
            System.out.println("Can't do that operation!");     
   }I commented out some other stuff I was thinking on, so just ignore. Thanks!

cuz you are not using the value returned by the DecimalFormat object.
                  df.format(answer2);
                  JOptionPane.showMessageDialog(null, inputString + " = " + (answer2));DecimalFormat.format() returns a string. By what magic do you think the primitive double answer2 is going to be changed to a String object?
                  String a2 = df.format(answer2);
                  JOptionPane.showMessageDialog(null, inputString + " = " + (a2));

Similar Messages

  • I downloaded and paid for an app on my ipad, how can I get it free on my iphone without using itunes as my laytop is broken. I cannot seem to find the purchase tab in app store? I am logged in using the same ID

    I downloaded and paid for an app on my ipad, how can I get it free on my iphone without using itunes as my laytop is broken. I cannot seem to find the purchase tab in app store? I am logged in using the same ID

    First, the app must be universal...designed for both iPhone/iPad:
    Tap App Store.
    Make sure you're signed in with the same Apple ID used for the original purchase.
    Tap Updates.
    Tap Purchased on the resulting screen.
    Locate the app in your Purchased tab.
    Tap the download icon.
    The app will begin downloading and you'll be taken back to your home screen.

  • I have an old iPod Classic with 80 GB (I think) of space. I saved all my songs in an external hard drive, but the iTunes library resided in an old computer (no longer working). Can I get the libray from my iPod and use it in my new computer (Windows)?

    I have an old iPod Classic with 80 GB (I think) of space. I saved all my songs in an external hard drive, but the iTunes library resided in an old computer (no longer working). Can I get the library from my iPod and use it in my new computer (Windows)?

    You might want to check your process for moving your iTunes music against this: http://support.apple.com/kb/HT4527.

  • I have imported contacts from Outlook to Mail and they have synced via iCloud to my iPhone 3GS. I can't get my iPhone to make a call using these contacts but if I dial the number of any of the contacts on the keypad, the call DOES work! Help me please!?

    I have imported contacts from Outlook to Mail and they have synced via iCloud to my iPhone 3GS. I can't get my iPhone to make a call using these contacts (it tries but then says call ended) but if I dial the number of any of the contacts on the keypad, the call DOES work! Help me please - is there something I need to do to the contacts because tehy came from Outlook? Thanks

    Thank you for replying.    Yes I deleted the old email address..   

  • Can you get an iphone 5 at target that uses AT&T or Verizon network and use the Straight Talk plan from Walmart?

    Can you get an iphone 5 at target that uses AT&T or Verizon network and use the Straight Talk plan from Walmart? I don't have AT&T or Verizon network and I don't want to get them but I was just wondering if you can get the iphone 5 that is at target and use it for the straight talk plan. I will be getting the straight talk plan but I would like to do some research on the iphone 5 first for straight talk. At walmart the phone is $544.99 and I think it will be a lot cheaper to buy it at target.
    Thank You!

    When I use find file http://www.macupdate.com/app/mac/30073/find-file (which does tend to find files that "Finder" can't), it's not coming up with any other itunes library files that have been modified in the past week, which I know it would have been - unfortunately, I don't have a very recent backup of the hard drive.  It would be a few months old so it wouldn't have the complete library on it....any ideas?  I'm wondering if restarting the computer might help but have been afraid to do so in case it would make it harder to recover anything...I was looking at this thread https://discussions.apple.com/thread/4211589?start=0&tstart=0 in the hopes that it might have a helpful suggestion but it's definitely a different scenario.

  • How Can I Get the Amount of Free Disk Space Using space using windows 7 please share example using GetDiskSpace

    How Can I Get the Amount of Free Disk Space  using windows 7 please share example using GetDiskSpace i have already studied http://digital.ni.com/public.nsf/allkb/9958B8E473C4EF1786256BBC0053B64F

    Reading your question a bit more in detail, I doubt whether you are using Win32 API GetDiskFreeSpace function (for which my previous post is the solution) of Programmer's Toolbox GetDiskSpace function.
    With reference to the second one, it works even with disks larger than 2GB but you need to use the proper formatting code to display the returned value. I updated my example to show total free space in the debug output window and added a comparison with 3GB value using UInt64TypeCompareUInt from the Programmer's Toolbox.

  • Can't get duplex print option for pdf files using  Adobe ReaderXI 11.0.04, Mac 10.8.5 with HP8600

    I get two-sided option for normal printing, but
    I can't get duplex print option for pdf files using  Adobe ReaderXI 11.0.04, Mac 10.8.5 with HP Officejet Pro 8600.  HP says it's an Adobe problem. I'm stuck.
    Thanks in advance.
    VO

    It depends where the pdf is located. If in the Finder or in an attachment to
    an email in Entourage, the message is ³You can¹t open the application
    ³Acrobat Reader 5.0² because PowerPC applications are no longer supported².
    If an attachment in an email that has come via Safari, the message is
    ³Safari can¹t open the file because no available applications can open it².
    In each case the menu bar is Finder or Entourage or Safari as the case may
    be.

  • How can I get a Windows Vista 32 bit version of Photoshop, please?

    How can I get a Windows Vista 32 bit version of Photoshop, please?

    Hi Kevinhannan,
    No current Photoshop supports this configuration.
    Photoshop CS5 was the last version of Photoshop to support Windows Vista.
    Photoshop Elements 12 was the last version of Photoshop Elements to support Vista as well.
    We no longer offer Photoshop CS5 or Elements 12.
    You might look at Amazon to see if you can get either product listed above. Just be careful when purchasing, make sure you know who you're buying from!
    Regards,
    Pete

  • HT201269 Hello in trying to restore from backup to my new phone I'm receiving a 'restore failed' message which I can't get rid off to start again.  Any ideas please?

    Hello in trying to restore from backup to my new phone I'm receiving a 'restore failed' message which I can't get rid off to start again.  Any ideas please?

    Hi there HotFerrari,
    It sounds like you are unable to restore your device from a backup you have in iTunes. I recommend the troubleshooting from the article named:
    iOS: If you can't back up or restore from a backup in iTunes
    http://support.apple.com/kb/ts2529
    Thank you for using Apple Support Communities.
    Cheers,
    Sterling

  • HT4623 I don't have a update software in my general settings G3 phone and can't get past up date 4.2.1 using itunes all I want is to download the free skype app

    I don't have a update software in my general settings G3 phone and can't get past up date 4.2.1 using itunes all I want is to download the free skype app

    iOS 4.2.1 is the latest for the iPhone 3G.

  • Where can I get serial number for Lightroom to start using it?

    Hello. I have just created Adobe CC account and purchased a Photography membership plan for Individuals. The price is 9,99 per month and this sum has already been taken from my card. On this page (https://accounts.adobe.com/plans) I can see the confirmation that I have obtained this plan.
    Now I want to use Lightroom but it asks me for serial number. After reading some help I found that I should get serial number from here - https://www.adobe.com/account.html. But on this page it says that "You have no registered products.". So I see no serial number.
    So there's a simple question - where can I get serial number for Lightroom to start using it?

    Jeff, thanks for your answer but it doesn't help. I've successfully passed all checks on page Sign in, activation, or connection errors | CS5.5 and later . My internet connection is ok, hosts file ok, certificates ok, etc. It's not a source of the problem.
    I've found that on page Adobe ID it says that I have free membership. Somehow it turns that my purchased Photography membership plan is not there at all. in order to proof that I really purchased it please see screen from my internet-banking page below:
    Why it is displayed only free membership in my account page and not Photography subscription which was already paid?

  • How can I get the adobe audition software which is used for editing a sound track?

    How can I get the adobe audition software which is used for editing a sound track?

    Hi pravupada,
    You can download Audition software from : Free Audition CC | Download Adobe Audition free trial
    Regards,
    Rave

  • HT200246 I JUST PURCHASED MOTION 5 AND HAVE NEVER USED IT OR ITS PREDECESSORS BEFORE.  HOW CAN I GET A LESSON GUIDE FOR HOW TO USE THIS SOFTWARE?

    I JUST PURCHASED MOTION 5 AND HAVE NEVER USED IT OR ITS PREDECESSORS BEFORE.  HOW CAN I GET A LESSON GUIDE FOR HOW TO USE THIS SOFTWARE?

    There are a number of resources.  You might want to start with:
    The User Manual:
    http://help.apple.com/motion/mac/5.0/en/motion/usermanual/
    This Thread:
    https://discussions.apple.com/message/22833760#22833760
    or just do a google search, that should bring up plenty of tutorials from around the web.
    Cheers!

  • When I go to update my apps on itunes, it says my account has been disabled. I've done everything I know to do to no avail. I've changed passwords, I've done it all about a hundred times, but I can't get to the bottom of it...HELP Please :)

    Hi,
    I am about to pull my hair out. My itunes account has been disabled............or at least that's what it says everytime I want to update my apps....I can't do it. Then it sends me to a useless web address www.apples.com/itunes/storesupport/forassistance it never helps me. I've changed my password, etc. But I can't get my apps updated or the "Apple" in the sky to fix it...I don't know where to go for customer service....Any suggestions?
    Thanks
    Kathy

    I updated the software on my iphone4 tonight and ran into this same endless loop - "itunes terms & conditions have been changed" - go to itunes, aceept - back to the "T&C have been changed message" with no ability to do anything in the app store until I accepted the new terms.
    While not a very direct solution, I was able to finally accept the terms in a way that seem to register with apple by making a purchase through iTunes on my computer. This forced me through updating my payment information and updating my iTunes software to the latest edition (which I had not yet taken the time to do).  After doing both of these, iTunes took me through the terms & conditions on two separate pages, but ultimately allowed me to purchase my song.  Once I completed these steps, it fixed the problem on my phone, so now I can update my apps and download new ones without running into that loop.
    Hope this helps!!!

  • How can i get data from another database SQL Server use database link from

    I have a database link from Oracle connect to SQL Server database with user cdit connect default database NorthWind.How can I get data from another database(this database in this SQL Server use this database link)?

    hi,
    u should see following documentation:
    Oracle9i Heterogeneous Connectivity Administrator's Guide
    Release 1 (9.0.1)
    Part Number A88789_01
    in it u just go to chapter no. 4 (using the gateway),,u'll find ur answer there.
    regards
    umar

Maybe you are looking for