Find the answer to your Linux question:
Results 1 to 3 of 3
hi there i have a java question that i need help with. i am trying to convert a double to time. so for example my result comes out like 3.18 ...
  1. #1
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119

    [SOLVED] Convert Double to Time

    hi there i have a java question that i need help with.

    i am trying to convert a double to time. so for example my result comes out like 3.18 hours. so how i could convert that to time? i wanted to be formatted like HH MM SS.

    thanks for your help in advance.

  2. #2
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119
    so i was able to figure it out by myself ......... but i am getting the wrong output.

    the problem that i am having is with one variable that is screwing everything up.

    here is my problem...
    Code:
    double distance = 10.0;
    double walking = (distance/3.14);
    int walking_ts = (int)walking*3600;
    int walking_h = (int)(walking_ts/3600);
    int walking_m = (int)((walking_ts%3600)/60);
    int walking_s = (int)(walking_ts%60.0);
    and when i check "walking_ts" i am getting 10,800 seconds instead of 11,448 seconds.

    any thoughts why i am getting the wrong output on my variable?

  3. #3
    Linux Newbie
    Join Date
    Dec 2006
    Posts
    119
    i guess i solve my own problem .

    all i had to do was change
    Code:
    int walking_ts = (int)walking*3600;
    to...
    Code:
    int walking_ts = (int)(walking*3600);
    and yes all i did was to add parentesis to it :S, how weird. for some odd reason the variables were passing somewhere.

Posting Permissions

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