B4J Question Format a time: got from a game a timevalue as Float

DonManfred

Expert
Licensed User
Longtime User
Format a time: got from a game a timevalue as Float while capturing game data from a running racing game...

In the documentation of the datastruct i found this info
[ UNITS = seconds ] [ RANGE = 0.0f->... ] [ UNSET = -1.0f ]

How do i format this to a time output of mm.ss.mmm (mnutes, Seconds, microseconds)?
 

Roycefer

Well-Known Member
Licensed User
Longtime User
B4X:
Dim secondsLeft As Double = FloatValueFromGame   'Casting to Double for better precision in math
Dim minutes As Int = secondsLeft/60
secondsLeft = secondsLeft - minutes*60
Dim seconds As Int = secondsLeft
secondsLeft = secondsLeft - seconds
Dim milliSeconds As Int = secondsLeft*1000       'I'm assuming you meant milliseconds since you specified 3 digits in the format
                         'Change 1000 to 1000000 if you really want microseconds, but you'll need more than
                         '3 digits to fully represent all possible microsecond values
Dim formattedString As String = NumberFormat2(minutes,2,0,0,False) & "." & NumberFormat2(seconds,2,0,0,False) & _
          "." & NumberFormat2(milliSeconds,3,0,0,False)
Log(formattedString)

As usual, beware: wildly untested.
 
Last edited:
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
little bit shorter, RTime are the seconds...
B4X:
    Dim hh, mm, ss As Int
    hh =  RTime/3600
    mm = (RTime mod 3600)/60
    ss = ((RTime mod 3600) mod 60)
    lblTime.Text = "Gesamtzeit: " &NumberFormat(hh,2,0) &"h "& NumberFormat(mm,2,0) &"m " '& NumberFormat(ss,2,0)&"s"
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
little bit shorter, RTime are the seconds...
But it does not show milliseconds then, right?

The data (seconds) is a Float value giving for ex. the "Last Sector time" from a F1-Race... It usually dont reach a Hour. You must drive VERY slow to reach such timings :D
But the output must be more precise then just showing the seconds...
The results from @Roycefer code 00:15:493 (Minutes:Seconds:milliseconds) is more what we need
 
Upvote 0
Top