07-18-2022, 06:15 PM
(07-18-2022, 05:06 PM)arnoldhf Wrote: Here is a snippet from QB that I executed in QB:
a = 91234.56
b$ = MKD$(a)
1 c = CVD(b$)
2 PRINT c
PRINT b$
OPEN "O", 1, "testmkd" 'sent it a file
WRITE #1, b$
CLOSE 1
The result of lines 1-2 correctly yields the proper value of "a".
--------------------------------------------------------------------------------------
Here is the QB64 code I used to test b$ that I wrote to the file:
Open "I", 1, "testmkd"
Input #1, b$
1 Print CVD(b$)
2 Print CVDMBF(b$)
close 1
OUTPUT:
-7.6795... D-226 (line 1)
91234.5625 (line 2)
As you can see only line 2 correctly interpreted the string b$ back to the original value of a in QB.
Arnold
The problem is that your default variable type is SINGLE, instead of a DOUBLE. Try this:
Code: (Select All)
Dim As Double a, c
Dim As Single lookieHere
Print "************************** WRITING"
a = 91234.56
b$ = MKD$(a)
c = CVD(b$)
Print c
Print b$
Open "O", 1, "testmkd" 'sent it a file
Write #1, b$
Close 1
Print "************************** READING"
Open "I", 1, "testmkd"
Input #1, c$
Print CVD(c$)
Print c$
'Print CVDMBF(c$)
Close 1
Print "************************** DEBUGGING"
a = 91234.56
lookieHere = 91234.56
b$ = MKD$(a): d$ = MKD$(lookieHere)
c = CVD(b$): d = CVD(d$)
Print c, d
Color 4
Print b$, d$
Color 7
Print
Print
Print "As you can see, CVD gives much different results when used with a SINGLE variable type, as with a DOUBLE variable type."
Print
Print "Make certain you use it with DOUBLE variable types, and your issue will go away."
MKD$ produces vastly different strings when passed a SINGLE value and when passed a DOUBLE value. If you're going to make doubles into a string, be certain it pass it double type variables to begin with. (Or else use MKS$ to make SINGLE types into a string.)