Getting rid of decimal from double, and turning it into an Integer?

Discussion in 'Plugin Development' started by Blockhead7360, Sep 29, 2015.

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

    Blockhead7360

    Hey! I was wondering if there is any way to get rid of the decimal from a double (even if it is .0), and turn it into an integer? I don't need any rounding, just no decimal.

    Also, I was wondering if this would work:
    Code:
    int example = 296;
                        Double doub = example * 0.125;
                        
    Can you transfer from the int into a double like that, even if the multiplication does not return a decimal?

    Please help, thanks :D
     
  2. Offline

    srspore

    You can cast a double to an int with
    Code:
    int someInt = (int) someDouble;
    This will set the value of "someInt" to the whole number value of "someDouble" and totally ignore any decimal it has.
    Also I think Java is smart enough for that multiplication thing to work. I think it will convert "example" to a double and then multiply it.
     
    Blockhead7360 likes this.
  3. Offline

    Blockhead7360

    @srspore okay thanks. I haven't tried it out yet, but I'm sure what you said will work ;)
     
Thread Status:
Not open for further replies.

Share This Page