convert jsp load time from ms to seconds results in 0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keydrive
    New Member
    • Oct 2007
    • 57

    convert jsp load time from ms to seconds results in 0

    On a jsp page, I declare a startTime variable and an endTime variable. The difference is then calculated and displayed in milliseconds.

    Code:
    (endTime.getTime() -  startTime.getTime())
    .... say that equals 208 ms

    if I want the date represented in seconds I can simply divide the total by 1000.

    Problem is when it's below 1000 such as the example above the value returned for display is 0 sec.

    Do I need to set the decimal point somewhere?
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by keydrive
    On a jsp page, I declare a startTime variable and an endTime variable. The difference is then calculated and displayed in milliseconds.

    Code:
    (endTime.getTime() -  startTime.getTime())
    .... say that equals 208 ms

    if I want the date represented in seconds I can simply divide the total by 1000.

    Problem is when it's below 1000 such as the example above the value returned for display is 0 sec.

    Do I need to set the decimal point somewhere?
    The problem is that when you do integral division, like long/long:
    Code:
    long interval = ...
    double seconds = interval/1000;
    The division is integral division -- the result is a long and any remainder is dicarded. The solution is to do floating point division, like double/double:
    Code:
    double interval = ...
    double seconds = interval/1000.0;

    Comment

    • keydrive
      New Member
      • Oct 2007
      • 57

      #3
      Hi BigDaddyLH,

      That did the trick.

      Thanks for the explanation.

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        ............... .........Right on!

        Comment

        Working...