Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help on Decimal Values - JOptionPane

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help on Decimal Values - JOptionPane

    Hi,

    I am a beginner in Java and I am currently learning about JOption pane. I have this below question plz.

    Using Strings I am accepting an input from the user and by using the Interer.ParseInt(variable) option I am able to multiply this two strings using the code below.

       String Length;
       Length = JOptionPane.showInputDialog("Enter the Length");
       String Breadth;
       Breadth = JOptionPane.showInputDialog("Enter the Breadth");
       System.out.println(" Area is " + (Integer.parseInt(Breadth) * Integer.parseInt(Length)));
       System.exit(0);

    Now My question is... How Do I make my code accept Decimal values. E.g. My Code should accept 10.02 as Length and 20.42 as Breadth and give the product a Decimal. How Do I do this???

    Appreciate the help.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help on Decimal Values - JOptionPane

    There are classes for other numeric data types besides Integer. Look at the Float and Double classes for methods like you are using from the Integer class.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Ranjith Kumar (July 1st, 2014)

  4. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help on Decimal Values - JOptionPane

    Thank You :-)

Similar Threads

  1. How to input a decimal via JOptionPane and echo it as a Integer
    By quantamphysics in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 2nd, 2013, 07:55 PM
  2. convertion hexadecimal to decimal and binary to decimal
    By Md.Ashraful Haque in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 13th, 2013, 07:30 AM
  3. Convert decimal values to english text
    By tqa in forum Java Theory & Questions
    Replies: 5
    Last Post: May 10th, 2012, 03:20 AM
  4. In jsp page After decimal i need only 2 values(for ex:477.74)
    By shashib09 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: August 23rd, 2011, 06:00 AM
  5. How do i show all the values in one window(JOptionPane)??
    By Antonioj1015 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 25th, 2009, 09:24 PM