Jump to content

Why is this returning 0


skillerkidos1

Recommended Posts

33 minutes ago, Gunman said:

Isn't it because they're int and ints can't be decimals? So it defaults to  int prayerPercent = 100 * 0; basically?

 

26 minutes ago, Malcolm said:

problem is when you're doing dynamic / static and you don't cast that value to a double that will return 0 due to rounding.

Even if it's 0.999999 it will round down to zero.

 

You need to cast your calculation to a double for dynamic / static and then multiply it by 100 and cast it back to an int.

Example here:


public int getPercentage() {
   double staticP = getSkills().getStatic(Skill.PRAYER);
   double dynamicP = getSkills().getDynamic(Skill.PRAYER);
   return (int) (100 * (dynamicP / staticP));
}

 

Ohhh I see now thank you very much <3

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...