- I do not want to convert a DOUBLE to a ULONGINT !!!
I want to translate a DOUBLE's fractional digits to a ULONGINT.
e.g. 0.876399937 ==> 876399937ull
I can get there by multiplying a DOUBLE by a large ULONGINT CONST... but I would have to use a STRING version of the DOUBLE's fractional digits to get the length so that I could use the correct CONST for that set of digits. Because, without being able to choose the correct CONST for each set of digits, I sometimes end up with ULONGINT results that are too large - or sometimes with rounding errors. [see output examples below].
Code: Select all
dim d as double
dim dsu as ulongint
dim dmu as ulongint
print "Translate a DOUBLE's fractional digits to ULONGINT representation:"
print "1. RND() DOUBLE"
print "2. DOUBLE fractional digits to STRING to ULONGINT"
print "3. DOUBLE Multiplied by CONST to ULONGINT"
For i = 1 To 30
d = RND()
'DOUBLE to STRING to ULONGINT - EXACT representation of the DOUBLE digits.
dsu = CULngInt(mid(str(d), 3))
'DOUBLE Multiplied by CONST to ULONGINT.
' Sometimes an EXACT representation of the DOUBLE digits.
' Sometimes a ROUNDED representation of the DOUBLE digits.
' Sometimes 10 to 100 times greater than a representation of the DOUBLE digits.
' Attempted with various CONST values.
' Some result is always off.
dmu = d * 10000000000000000ull
print tab(9); d
print tab(12); dsu
print tab(12); dmu
Code: Select all
' Output examples:
'1. RND() DOUBLE
'2. DOUBLE fractional digits to STRING to ULONGINT
'3. DOUBLE Multiplied by CONST to ULONGINT
' 5324827746953815 'same
' 2956116099376232 'rounded up
' 6646097381599247 'rounded down
' 1796755751129240 'x10
' 5509635596536100 'x100