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: Calculationg the percentage.

  1. #1
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Calculationg the percentage.

    I am trying to calculate a percentage.

    double percentage = (numberMatchedEntries / numberEntriesFile1) * 100;
    numberMatchedEntries = 20
    numberEntriesFile1 = 52

    So the output would be about: 38.1%

    But from this code:
    (numberMatchedEntries / numberEntriesFile1)
    I only get 0 back, and not 0,381

    I tried using a float too, but it still keeps 0.
    And I realy don't know why?


  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: Calculationg the percentage.

    What data types are used in the formula? With integer arithmetic: 6/10= 0
    using doubles: 6.0/10 = 0.6
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Calculationg the percentage.

    That would be it.
    Those two are int's.
    I will change that.

    Thanks.

Similar Threads

  1. How to get a System's total CPU usage percentage using a java program
    By userj2ee in forum Java Theory & Questions
    Replies: 2
    Last Post: January 7th, 2011, 01:28 AM
  2. It's not printing out the correct percentage...
    By JBow94 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 15th, 2010, 04:07 PM
  3. No Percentage?
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 18th, 2009, 12:02 PM