VB6 - CDbl truncating problem
I'm having problems casting to a Double from a String in VB6.
dblValue = CDbl(strValue)
When strValue = 88888888888888888, dblValue = 8.88888888888889E+16, which is truncating the number during th开发者_StackOverflowe cast. Does anyone know of any way around this?
Thanks in advance!
You could change your code to use Decimal
instead of Double
. That data type has the necessary precision to store the value.
Unfortunately, VB6 does not support creating variables of type Decimal
directly, but you can store the data as a Variant
of subtype Decimal
, e.g.
Dim decValue As Variant
decValue = CDec(strValue)
You can manipulate this data exactly as you would any other numeric data type, you just won't have strict type-safety for the variables.
There is no way around this, because a Double is only precise to 15 significant figures, but 88888888888888888 has 17 digits. There will be precision lost if you convert the number to Double.
You should use a Decimal type by CDec
if you need to preserve all digits exactly.
精彩评论