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: Round Decimal number into 2 decimal

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Round Decimal number into 2 decimal

    dear all,
    here is my code and i want to convert number into 2 decimal but this code not give me result how can i do please check my code.




    import javax.swing.JOptionPane;
    public class showtime{
    public static void main(String[] args){

    double total_mili=System.currentTimeMillis();
    JOptionPane.showMessageDialog(null,total_mili, "Total milisecond",JOptionPane.INFORMATION_MESSAGE);

    double seconds=total_mili/60;
    double sec=(double)(seconds * 100) / 100.000;

    JOptionPane.showMessageDialog(null,seconds, "Total Second",JOptionPane.INFORMATION_MESSAGE);
    JOptionPane.showMessageDialog(null,sec, "Total Second",JOptionPane.ERROR_MESSAGE);
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,329
    My Mood
    Mellow
    Thanks
    253
    Thanked 781 Times in 766 Posts

    Default Re: Round Decimal number into 2 decimal

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Please clarify your question. Do you mean you only want to display the number to two decimal places?

  3. #3
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Round Decimal number into 2 decimal

    See Java program to format a double value to 2 decimal places

Similar Threads

  1. [SOLVED] Printing a Decimal Equivalent of a Binary Number
    By Arslan Ahmad 656 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 1st, 2014, 02:04 AM
  2. [SOLVED] How to round to 2 decimal places in a dialog box
    By JohnEliot in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 3rd, 2013, 07:39 PM
  3. 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
  4. Converting decimal number to m minutes, n.nn seconds format.
    By coreysizemore in forum Java Theory & Questions
    Replies: 1
    Last Post: January 20th, 2012, 11:37 PM
  5. take a double, then round decimal to either to .0 or .5 only
    By MaxBodine in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 30th, 2011, 04:35 PM