Solved Kill death/ratio not showing correctly, double not working?

Discussion in 'Spigot Plugin Development' started by mrdado243, Apr 21, 2017.

  1. So i'm making kill/death ratio on my server that is displayed by scoreboard but for some reason it's not working correctly it's not showing decimal value!
    i will upload screenshots of problem thanks for help!
    This is how it looks
    this is how it should be (google says so, .. lel)
    this is convertion
    • Agree Agree x 1
  2. This is because you're still just dividing integers, using
    Code (Text):
    should do the trick.
    • Like Like x 1
  3. uhm please check the code i need to get kill/death ratio and ints are full numbers so?
    • Like Like x 1
  4. Yeah... So convert them to a type that can represent decimals, the snippet I posted above will help you do this.
    • Agree Agree x 1
  5. When you write it to the scoreboard, what does that line look like?

    Do a system.out right after you assign kdr to its variable and see what it outputs to the console.

    Sent from my iPhone using Tapatalk
  6. it is getting values from config every 60 ticks while scoreboard updates.
    • Like Like x 1
  7. ok, .. so i should make int that devides 2 ints and than this double?
    • Like Like x 1
  8. Integers represent a whole number, therefore doing an integer division will result in a whole number. Hence why you are getting 2.0 because the result has been rounded. In order to get a decimal result you need to use types that can represent decimals.

    Code (Text):
    int kills = getConfig().getInt("playerkills." + p.getName().toLowerCase());
    int deaths = getConfig().getInt("playerdeaths." + p.getName().toLowerCase());
    double kda = Double.valueOf(kills) / Double.valueOf(deaths);
    The above should work.
    • Winner Winner x 1
    • Like Like x 1