Report post

Are you sure you want to report the post shown below? This will send an email to the ATVO administrators. Please include a short reason for reporting.

Users reporting for no reason may be locked out.


Post

Posted by Nick Thissen
on
The code won't just magically work if you copy/paste it, Simon posted that so you can see the logic we are using to convert "total seconds" (e.g. 84.384" into a laptime-like format (1:24.384).

The logic is pretty simple: we divide the total seconds by 60 and round down, and that gives the number of minutes:
min = (int) (seconds / 60);


Then we get the remainder of that division which gives the number of remaining seconds:
sectime = seconds % 60;


Then we just concatenate the whole thing together:
var sb = new StringBuilder(prefix);
if (min > 0)
sb.Append(min).Append(':').Append(sectime.ToString("0" + secFormat));
else
sb.Append(sectime.ToString(secFormat));


These parts you can almost copy/paste. The rest is just some logic to deal with different situations (sometimes we want the time with minutes, sometimes without, sometimes we want it positive, then negative, etc.)