Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default transforming double to int

    Hello guys! I want you to help me with something. I need to use the pow() method which can only be used with double data type. But I also need to use the result in a mod operation (%) which is only defined for int data type. So there must be a way to convert doubles to integers. Do you know how? thanks

  2. #2
    dmacvittie is offline Member
    Join Date
    Aug 2007
    Posts
    30
    Rep Power
    0

    Default

    Hello Alejandro,

    Try looking at Double.intValue() and Integer.doubleValue(). They should give you what you're looking for.

    Don.
    Don MacVittie F5 Networks - DevCentral

  3. #3
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Or you could always cast (although that is not as safe, since it can fail)
    Java Code:
    double d = 7.8;
    int i = (int) d;
    note: that wont round. it will give you 7, although it should give you 8 (since we round up).

Similar Threads

  1. Transforming XML to HTML
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-01-2008, 11:06 PM
  2. Replies: 3
    Last Post: 01-19-2008, 09:38 AM
  3. Calculating sin of a double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 09:13 PM
  4. Getting smallest possible Double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-06-2007, 03:15 PM
  5. How to round a double?
    By Valeriano in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •