Can I make a double a string also?

Discussion in 'Plugin Development' started by Mrcool234, Apr 20, 2014.

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

    Mrcool234

    Im making a KDR(Kill death ratio) and I have everything working except I need to put the KDR in front of the players name like a Prefix like "0.00 Mrjoecool234" but the e.getPlayer().setDisplayName(kdr); says I need to return a string but it's a double so how do i make a double return a string?

    thanks in advanced


    Pastebin: http://pastebin.com/xY5jZBy6
     
  2. Offline

    sipsi133

    Mrcool234
    Code:
     double yourdoublename = yourdoublevalue;
    String yourstringname = Double.toString(yourdoublename);
    And then you can use "yourstringname" for setting the displayname.
     
  3. Offline

    Mrcool234

    sipsi133
    Ok now it's giving me a / by zero error can you help me fix that?
     
  4. Offline

    hexaan

    Mrcool234

    You can do this in many different ways.

    Code:java
    1. e.getPlayer().setDisplayName(""+kdr);
    2. e.getPlayer().setDisplayName(Double.toString(kdr));
    3. e.getPlayer().setDisplayName(String.valueOf(kdr));
     
  5. Offline

    sipsi133

    Mrcool234 Can you show your code and error?
     
  6. Offline

    hexaan

    Mrcool234
    Is your int value of deaths 0?
    Code:java
    1. double kdr = kills / deaths;
     
  7. Offline

    mmiillkkaa

    Mrcool234 Make sure that "deaths" is never zero.
     
  8. Offline

    Konkz

    Just saying, what you shown us in the code would of changed it from
    konkz to 0.0 - you have to do
    PHP:
    e.getPlayer().setDisplayName(kdr " " p.getName());
     
  9. Offline

    Mrcool234

  10. Offline

    hexaan

    Mrcool234
    Code:java
    1. this.getConfig().getInt(".deaths")

    Is this a valid path?

    Should your code not look like this:
    Code:java
    1.  
    2. this.getConfig().getInt(playername+".deaths")
    3.  
     
  11. Offline

    Mrcool234

    hexaan
    Im reading your code and im reading my code I dont see exactly where i put that
     
  12. Offline

    AoH_Ruthless

    Mrcool234
    Your getting your config paths incorrectly ...

    getInt(".deaths"); is a null path so it is returning 0.


    What you have:
    Code:java
    1. getConfig().set(playername + ".kdr", getConfig().getDouble(playername + this.getConfig().getInt(".kills")/this.getConfig().getInt(".deaths")));


    You have to do:
    Code:java
    1. getConfig().set(playername + ".kdr", getConfig().getDouble(this.getConfig().getInt(playername + ".kills")/this.getConfig().getInt(playername + ".deaths")));


    But remember, because you are getting ints, the value will always be truncated; i.e 1/3 = 0, 7/5 = 1, etc..
    Therefore you have to to getDouble instead of getInt
     
  13. Offline

    Mrcool234

    Wait nevermind
     
Thread Status:
Not open for further replies.

Share This Page