Solved

Double type for whole number?

Posted on 2003-11-25
7
353 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now