tags:

views:

26

answers:

2

Hi, 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 the cast. Does anyone know of any way around this?

Thanks in advance!

+2  A: 

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.

KennyTM
+3  A: 

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.

Christian Hayter