Heart rounding

Discussion in 'Plugin Development' started by Retrosize, May 2, 2014.

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

    Retrosize

    Hello there, I'm having some problems with the hearts. I currently have the code all set out just that the hearts always go into decimals and never exactly round up nor down. I've tried the whole killer.getHealth()/2.0
    ^ Of course with having a variable that's killer
    but still no luck, any help?

    ;DR: How do I round hearts?
     
  2. Offline

    iFamasssxD

    Hearts are displayed in increments of 1, 1 increment = 1 half heart. As for rounding decimals you can use Math.round(value) and it will round it, or Math.floor(value) to round down and Math.ciel(value) to round up.
     
  3. Offline

    JBoss925

    Do iFamasssxD 's thing or if you want to see how it's working vvv
    Get the double as a string, use the "." as the split and then if number after the "." is 5 or greater add 1 to the first number and if not then just use the number in front go the "." BUT I SERIOUSLY RECOMMEND USING iFamasssxD 's METHOD AS THIS IS MUCH MORE COMPLICATED AND YOU ARE CONSTANTLY SWITCHING VARIABLE TYPES

    Ex:
    String -> 6.2
    Split at "."
    Double.valueOf("6") and Double.valueOf("2")
    2<5 thus we do not add 1 to 6
    Use first number 6
    6 is rounded number
    Get the Double.valueOf("6")

    String -> 20.6
    Split at "."
    Double.valueOf("20") and Double.valueOf("6")
    6>5 thus we do 20+1 =21
    Use 21
    21 is rounded number.
    Get the Double.valueOf("21")
     
    Retrosize likes this.
  4. Offline

    Retrosize

Thread Status:
Not open for further replies.

Share This Page