B4R Question Convert Ulong to string

janderkan

Well-Known Member
Licensed User
Longtime User
I read the time from a string to a Ulong.
I calculate the elapsed time as a Ulong.
I calculate newtime as Ulong = time + elapsed.
All works fine, but when I use Numberformat(newtime,1,0) to convert to string there is an error.

If I repeatedly call the sub the calculated newtime is correct
but newtime converted to string is always the same.

Test project attached.
 

Attachments

  • testtime.zip
    1,010 bytes · Views: 231

janderkan

Well-Known Member
Licensed User
Longtime User
Both a Double and a Ulong are 4 bytes.
Maybee my Ulong value is to large for a Double?
I created my own UlongFormat, is there a better way?

B4X:
Sub UlongFormat(Value As ULong) As String
    Dim digits(10) As Byte
    For count = 0 To 9
        digits(count) = Value / Power(10,9-count)
        Value = Value - digits(count) * Power(10,9-count)
        digits(count) = digits(count)+48
    Next
    Return BC.StringFromBytes(digits)
End Sub
 
Upvote 0
Top