Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

Double type for whole number?

Hi Experts,

Got some data by whole number calculation, I need to store the data in an array and some variables. The data are bigger than the max number in Long type.
Do you think I can use Double type to store the whole number without lossing the acuracy? say, would it store 333333333 as 333333332.9999999?
If it lost some acuracy I will get problem because I need to compare such stored data.
0
dartnut
Asked:
dartnut
2 Solutions
 
mccainz2Commented:
Double stores up to 14 decimal places (dependant on how many places you have to the left of the decimal)

as for inaccuracy , if it starts life as a whole number you should be fine ...

try...

Dim x As Double
 x = 333333333
MsgBox CDbl(x / 3)

and for comparison try

Dim x, y As Double
x = 3
y = 3.00000000000001
MsgBox CBool(x = y)
0
 
Z_BeeblebroxCommented:
If you are concerned about accuracy, you could use the Decimal type, which will store such numbers exactly, but with a large performance penalty.

Zaphod.
0
 
Arthur_WoodCommented:
just as a matter of note, the value 333333333 is NOT too large for a VB Long variable

Long Datatype has an UPPER limit of 2147483647, so 333333333  is well below that limit.

AW
                                                     
0
 
grayeCommented:
Floats, doubles, and decimals are not really well suited for storing big integers... their designs allow for the number of significant digits (the mantissa) portion to actually shrink/grow by 1 digit depending the sign and exponents.

There are lots of "big integer" libraries out there...  VB.Net is a better platform for doing this kind of stuff.  If you're interested, I've got some links/source code for big integer libraries in both VB6 and VB.Net

Just curious... how'd you get the numbers anyway... (since you've got to have 'em stored in a variable somewhere before you can put 'em in an array)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now