Discussion:
Saving value of a double to a text file
donJ
2017-04-26 20:06:24 UTC
Permalink
Hi,

What I would like to do is save the value of a double to a text file and
be able to retrieve it, but Str(d) seems to truncate the value to 7
digits. Format does the same, it just adds zeros.

I tried this code in a push button:

Dim d1, d2 as double
Dim s as string

d1 = 12345.12345
s = Str(d1)
d1 = val(s)

msgbox s //==> shows 12345.12 truncated to seven digits
//==> same result with the decimal in any position

d2 = 12345.12345
if d1 = d2 then
msgbox "yes"
else
msgbox "no" //==> they are not the same
end if

A double should have a precision of far more than seven digits, (I think
it's about 15).

What's the best way to save this value in a text file?


Thanks in advance,

Don



_______________________________________________

Xojo forum:

https://forum.xojo.com/
Bob Delaney
2017-04-26 20:44:14 UTC
Permalink
Try

s = Format(d1, "-#.##############e”)

Bob
Hi,
What I would like to do is save the value of a double to a text file and be able to retrieve it, but Str(d) seems to truncate the value to 7 digits. Format does the same, it just adds zeros.
Dim d1, d2 as double
Dim s as string
d1 = 12345.12345
s = Str(d1)
d1 = val(s)
msgbox s //==> shows 12345.12 truncated to seven digits
//==> same result with the decimal in any position
d2 = 12345.12345
if d1 = d2 then
msgbox "yes"
else
msgbox "no" //==> they are not the same
end if
A double should have a precision of far more than seven digits, (I think it's about 15).
What's the best way to save this value in a text file?
Thanks in advance,
Don
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum.x
donJ
2017-04-26 20:58:16 UTC
Permalink
Thank you, that did it.
I didn't know about the "e" at the end.
Don
Post by Bob Delaney
Try
s = Format(d1, "-#.##############e”)
Bob
Hi,
What I would like to do is save the value of a double to a text file and be able to retrieve it, but Str(d) seems to truncate the value to 7 digits. Format does the same, it just adds zeros.
Dim d1, d2 as double
Dim s as string
d1 = 12345.12345
s = Str(d1)
d1 = val(s)
msgbox s //==> shows 12345.12 truncated to seven digits
//==> same result with the decimal in any position
d2 = 12345.12345
if d1 = d2 then
msgbox "yes"
else
msgbox "no" //==> they are not the same
end if
A double should have a precision of far more than seven digits, (I think it's about 15).
What's the best way to save this value in a text file?
Thanks in advance,
Don
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

Loading...