Results 1 to 3 of 3
  1. #1
    RojBlake is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Default Removing decimals from double

    Hello!

    I've only just started learning Java, and I've just progressed from programs like "HelloWorld" and such

    I've written an extremely simple and basic program, that measures time dilation when a fictive space vessle travels close to the speed of light...
    It's working as I've intended, however, my ambition is to remove all decimals from the answer. For example if I get answer of 15.93848929393, I've used
    Math.floor to round the double off, however now it will be displayed as 15.0 and I would like to be rid of the decimal completely.
    Is there anybody who can give me a suggestion as to how to remove the decimal?
    Please bear with me, I'm a complete noob at this, and there's a lot I still don't know and understand...

    Here is the code:


    import javax.swing.*;
    import java.lang.Math;



    public class TimeDilation {
    public void dilation(){

    double speedoflight, result, round;



    speedoflight = Double.parseDouble(JOptionPane.showInputDialog("En ter lightspeed"));
    result = 100*(Math.sqrt(1-(Math.pow(speedoflight, 2))));
    round = Math.floor(result);






    JOptionPane.showMessageDialog(null, "If you travel for 100 years on Earth " + round + " years will pass on The Magellan");


    }

    }

    Thanks in advance for any replies!!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Removing decimals from double

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: Removing decimals from double

    rid of the decimal completely.
    Cast the double to an int
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Removing the double values?
    By Lund01 in forum Advanced Java
    Replies: 13
    Last Post: 11-17-2010, 12:34 PM
  2. Removing duplicates from double Arrays
    By jhong253 in forum New To Java
    Replies: 3
    Last Post: 10-30-2010, 11:32 PM
  3. BIG decimals
    By xael in forum New To Java
    Replies: 17
    Last Post: 10-04-2010, 11:14 AM
  4. Java/SQL Removing double data
    By Subhero in forum AWT / Swing
    Replies: 2
    Last Post: 05-13-2010, 04:44 PM
  5. get more decimals?!?! please help!
    By michcio in forum New To Java
    Replies: 7
    Last Post: 05-22-2008, 11:26 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
  •