Solved

Double type for whole number?

Posted on 2003-11-25
7
356 Views
Last Modified: 2010-05-01
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
Comment
Question by:dartnut
7 Comments
 
LVL 5

Accepted Solution

by:
mccainz2 earned 35 total points
ID: 9818902
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
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 9819278
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
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 35 total points
ID: 9819841
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
 
LVL 41

Expert Comment

by:graye
ID: 9835024
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question