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

Thread: what's wrong with my code?! OTL

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

    Question what's wrong with my code?! OTL

    I just started learning java because of school, and we have this machine exercise about money and denominations. My code seems right and no errors have been found. Moreover, when I input different numbers, the output is right except for one. When I input 2143.99, it adds up to 2143.98 only. I tried inputting 2143.98, and the output is correct. I tried 2143.97, but the output adds up to only 2143.96. I tried different decimals and I found out that it's correct for even-numbered decimals for 2143. I tried inputting 3143.99, 4143.99, 5143.99, and so on, and everything is correct. It seems like the only one wrong is 2143. Wth is wrong with it? HELP PLEASEEEE!


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: what's wrong with my code?! OTL

    It's really hard helping without seeing your code.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: what's wrong with my code?! OTL

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

  4. #4

    Default Re: what's wrong with my code?! OTL

    Quote Originally Posted by PhHein View Post
    It's really hard helping without seeing your code.
    Yeah. As A BEGINER OF JAVA, I also want to learn something about your problem. You may give us your code

  5. #5
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: what's wrong with my code?! OTL

    You are probably using floating point numbers. Floating point numbers are not 100% accurate and certain values simply can not be represented with these.
    If you want a soluton that is 100% accurate you should read up on Fixpoint numbers or BigDecimal.

Similar Threads

  1. what is wrong with this code?
    By Linus in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 18th, 2013, 05:28 PM
  2. What is wrong with my I/O code?
    By shimazaky in forum What's Wrong With My Code?
    Replies: 11
    Last Post: August 29th, 2013, 07:32 AM
  3. There are something wrong with my code...
    By khanhnq in forum Object Oriented Programming
    Replies: 0
    Last Post: January 13th, 2013, 09:04 PM
  4. Please what is wrong with my code
    By LordDavid in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 28th, 2012, 09:08 PM
  5. need help .. what is wrong with my code.
    By baig-sh in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 10th, 2011, 07:28 PM

Tags for this Thread