Solved Percentage

Discussion in 'Spigot Plugin Development' started by MadMaxCookie, May 28, 2016.

  1. Hello so I'm trying to make a percentage but I don't what's the method to what I'm trying is

    I'm trying this one

    Code (Java):
    Percentage = 100%;

    if(percentage is 20%) {
    // do something
    }
    any idea how to do this ?
     
  2. Could you just do this:
    Code (Text):
    double percentage = 1.00; //100%

    if (percentage == 0.2) {
         //do stuff
    }
    All percentage is, is a linear multiplier.

    Example:
    10% is 0.1
    15% is 0.15
    73.2% is 0.732
    1% is 0.01
    etc
     
    • Funny Funny x 1
  3. without random ?
     
  4. Could you elaborate or reword what you are trying to accomplish? :)

    I'm having a little trouble trying to figure out exactly what your issue is.
     
  5. Code (Text):
    double random = Math.random();
    if(random <= 0.2){
      //Do something (20% chance)
    }
    The code in the if clause would fire with a 20% chance.
     
    • Agree Agree x 3
    • Informative Informative x 1
  6. right now I think its not needed
    your method will only work if I change the 1.00 to another double.
    this is what I'm trying to do Random.