Results 1 to 3 of 3

Thread: double Problem

  1. #1
    MGT Madness is offline Member
    Join Date
    Oct 2013
    Posts
    10
    Rep Power
    0

    Default double Problem

    Java Code:
    double absorbPercent;
    absorbPercent = 122/545;
    System.out.println(absorbPercent);
    122/545 is suppose to give me 0.223853211 but it gives me 0.0
    If it is possible, what i only want is for it to store 2 decimal places after the 0.
    So 0.22


    - Thank you for your time!

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: double Problem

    122 and 545 are both integers. int/int = int

    -->
    absorbPercent = 122./545
    or
    absorbPercent = (double)122/545;
    or
    .....

  3. #3
    MGT Madness is offline Member
    Join Date
    Oct 2013
    Posts
    10
    Rep Power
    0

    Default Re: double Problem

    Quote Originally Posted by eRaaaa View Post
    122 and 545 are both integers. int/int = int

    -->
    absorbPercent = 122./545
    or
    absorbPercent = (double)122/545;
    or
    .....
    Thank you mate!
    I will look into this, i appreciate your help :)

Similar Threads

  1. Problem multiplying a double
    By TheKingpin in forum New To Java
    Replies: 4
    Last Post: 10-10-2012, 09:51 AM
  2. Double Array problem
    By AlinkaTroll in forum New To Java
    Replies: 6
    Last Post: 05-03-2011, 01:58 AM
  3. Double drawing problem with 2D
    By leapinlizard in forum Java 2D
    Replies: 4
    Last Post: 02-12-2010, 01:02 AM
  4. variable double problem
    By DarkoDrljaca in forum New To Java
    Replies: 5
    Last Post: 03-02-2009, 08:00 AM
  5. Double Value problem
    By sakthivel123 in forum New To Java
    Replies: 2
    Last Post: 07-10-2008, 04:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •