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 2 of 2

Thread: Math.round...I need help understanding what I am doing wrong and why it's not working

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Math.round...I need help understanding what I am doing wrong and why it's not working

    Hi, I don't understand what am I doing wrong, I just can't get the right answer no matter what I change. Here is the code:

     
    import java.io.*;
    import static java.lang.System.*;
     
    import java.util.Scanner;
     
     
    import java.lang.Math;
     
     
    class Assignment2 {
     
         public static void main (String str[]) throws IOException {
             Scanner scan = new Scanner(System.in);
     
     
     
     
     
     
           System.out.println("Please enter two decimal");
     
     
     
     
          double x = scan.nextDouble();
         double y =scan.nextDouble();
          int temp = (int)Math.round(100*x);
     
         System.out.println(1.0*(200-temp)/100);
         System.out.println((y - x));
     
     
     
     
     
     
     
         }
     
    }

    I am getting .53 and I should be getting 0.527
    Anyone explanation and/or feedback, will be greatly appreciated. I have tried everything but can't get 0.527

    Thanks
    Hilda


  2. #2
    Member
    Join Date
    Aug 2013
    Location
    Reykjavik, Iceland
    Posts
    51
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default Re: Math.round...I need help understanding what I am doing wrong and why it's not working

    Try to compress your code a little bit, so it will be better to read.

    I'm not sure if you need to import all that stuff, try looking at that.

Similar Threads

  1. Is My Math Wrong?
    By grayaa93 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 13th, 2013, 11:07 PM
  2. [SOLVED] How to make Math.round() round to the nearest .1?
    By bdennin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 2nd, 2013, 07:23 PM
  3. Math operations not working..
    By tyeeeee1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 13th, 2012, 12:41 PM
  4. Need help understanding math.random method.
    By slashdash in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 23rd, 2012, 05:50 PM
  5. Need Help Understanding Where I went wrong
    By basedoverlord12 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 1st, 2011, 06:40 PM

Tags for this Thread