Jump to content

Why is this returning 0


Recommended Posts

Posted
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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