I don't know how to make the kd

Discussion in 'Plugin Development' started by Marv1nYT, Jul 25, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Marv1nYT

    Hello, I don't know exactly what I did wrong, but the KD is always only "0.0".
    I want the KD to be displayed in this format: 0.12
    But I don't know how I do this exactly. Here's my code:
    Code:
    public class Stats {
       
        public static Double getKD(String uuid) {
            if(getDeaths(uuid) == 0) {
                return Double.valueOf(getDeaths(uuid).intValue());
            } else {
                double kd = Double.valueOf(getKills(uuid).intValue() / getDeaths(uuid).intValue());
                kd = Double.valueOf(Math.round(100.0D * kd) / 100.0D);
                return kd;
            }
        }
       
        public static Integer getKills(String uuid)
          {
            Integer i = Integer.valueOf(0);
            if(MySQL.playerExists(uuid))
            {
              try
              {
                ResultSet rs = Main.mysql.query("SELECT * FROM SkyPvPStats WHERE UUID= '" + uuid + "'");
                if ((rs.next()) && (Integer.valueOf(rs.getInt("KILLS")) == null)) {}
                i = Integer.valueOf(rs.getInt("KILLS"));
              }
              catch (SQLException e)
              {
                e.printStackTrace();
              }
            }
            else
            {
            MySQL.createPlayer(uuid);
              getKills(uuid);
            }
            return i;
          }
         
          public static Integer getDeaths(String uuid)
          {
            Integer i = Integer.valueOf(0);
            if (MySQL.playerExists(uuid))
            {
              try
              {
                ResultSet rs = Main.mysql.query("SELECT * FROM SkyPvPStats WHERE UUID= '" + uuid + "'");
                if ((rs.next()) && (Integer.valueOf(rs.getInt("DEATHS")) == null)) {}
                i = Integer.valueOf(rs.getInt("DEATHS"));
              }
              catch (SQLException e)
              {
                e.printStackTrace();
              }
            }
            else
            {
            MySQL.createPlayer(uuid);
              getKills(uuid);
            }
            return i;
          }
    
    }
     
  2. Offline

    CraftCreeper6

    @Marv1nYT
    Try to remove the rounding math.
     
  3. Offline

    Marv1nYT

    @CraftCreeper6
    Thanks, but how do I get the numbers after the comma?
     
  4. Offline

    CraftCreeper6

    The comma? Do you mean decimal place?
    You could create your own rounding function, or, you could just substring 2 decimals

    Sent from my LYA-L09 using Tapatalk
     
  5. Offline

    KarimAKL

    What do you need them for?
     
Thread Status:
Not open for further replies.

Share This Page