So I’m getting closer and closer to making the timer work the way I want it to, with one small problem.
I found the following post about returning millisecond and nanosecond:
How do you convert Stopwatch ticks to nanoseconds, milliseconds and seconds?
But what I’m trying to do is show only the 10ths of 100ths of a second when desired.
I have the following code:
Private Sub TotalTimer_Tick(sender As System.Object, e As System.EventArgs) Handles TotalTimer.Tick
Dim elapsed As TimeSpan = Me.matchStopwatch.Elapsed
Me.MatchClockLbl.Text = String.Format("{0:0}:{1:00}:{2:00}.{3:###}", _
Math.Floor(elapsed.TotalHours), _
elapsed.Minutes, _
elapsed.Seconds, _
(elapsed.Milliseconds / 100))
End Sub
Now I tried to change the part of code from {3:000} to {3:0} or {3:00} but all this does is change format, it doesn’t actually remove the 1000ths digit or 1000ths digit, they still show up.
I further found this on the MSDN:
http://msdn.microsoft.com/en-us/library/ee372287.aspx#fSpecifier
But I keep getting s.f or s/f or something that’s not right.
EDIT: Added in the modified version of the code, thanks Oded. The new problem now is that the label likes to flicker the extra digits once in a while.
Divide
Millisecondsby 10 to get 100th of a second and by 100 to get 10th of a second.This works by integer division – essentially throwing away the least significant digits and assumes
Millisecondsreturns at most 3 digits.