|
-
Apr 15th, 2005, 06:26 AM
#1
Thread Starter
Fanatic Member
what variable should I use?
hello,
I need a variable that will be able to reach values of billions...
(10,000,000,000) what variable should I use? integer? long?
thanks
Last edited by dekelc; Apr 15th, 2005 at 06:39 AM.
Dekel C.
-
Apr 15th, 2005, 06:38 AM
#2
Re: what variable should I use?
If you need fractional (floating-point) values - Single.
Otherwise, Long.
-
Apr 15th, 2005, 06:47 AM
#3
Frenzied Member
Re: what variable should I use?
Code:
Integer (short integer)
2 bytes -32,768 to 32,767
Long (long integer)
4 bytes -2,147,483,648 to 2,147,483,647
Single (single-precision floating-point)
4 bytes -3.402823E 38 to -1.401298E-45 for negative values
1.401298E-45 to 3.402823E 38 for positive values
Double (double-precision floating-point)
8 bytes -1.79769313486232E 308 to -4.94065645841247E-324 for negative values
4.94065645841247E-324 to 1.79769313486232E 308 for positive values
Integers offer a smaller range and steps of 1.
Floats offer very large ranges.
At low values their steps are very small and at high values their steps are very big.
They're all signed.
Last edited by jeroen79; Apr 15th, 2005 at 06:51 AM.
-
Apr 15th, 2005, 06:49 AM
#4
Re: what variable should I use?
10,000,000,000 requires a Single data type.
-
Apr 15th, 2005, 06:50 AM
#5
Re: what variable should I use?
 Originally Posted by dekelc
hello,
I need a variable that will be able to reach values of billions...
(10,000,000,000) what variable should I use? integer? long?
thanks

What are the accuracy requirements in division and multiplication for the values you will be holding?
-
Apr 15th, 2005, 06:53 AM
#6
Re: what variable should I use?
This might be your best choice - single and double are evil...
Decimal Data Type
Decimal variables are stored as 96-bit (12-byte) signed integers scaled by a variable power of 10. The power of 10 scaling factor specifies the number of digits to the right of the decimal point, and ranges from 0 to 28. With a scale of 0 (no decimal places), the largest possible value is +/-79,228,162,514,264,337,593,543,950,335. With a 28 decimal places, the largest value is +/-7.9228162514264337593543950335 and the smallest, non-zero value is +/-0.0000000000000000000000000001.
Note At this time the Decimal data type can only be used within a Variant, that is, you cannot declare a variable to be of type Decimal. You can, however, create a Variant whose subtype is Decimal using the CDec function.
-
Apr 15th, 2005, 06:56 AM
#7
Re: what variable should I use?
What's evil about a single/double? They're smaller than the decimal type (4/8 bytes vs 12).
Edit: also just read (in your post) that they need to be stored in a Variant. Now if anything's evil, that is
-
Apr 15th, 2005, 07:03 AM
#8
Frenzied Member
Re: what variable should I use?
Floats lose precision at large values.
Code:
really: 990 + 990 = 1980
float: 99E1 + 99E1 = 19E2
990 + 990 = 1900
Imagine losing €80 after a deposit if your bank stores your account as a float.
Getting out of debt would be easy though.
-
Apr 15th, 2005, 07:03 AM
#9
Re: what variable should I use?
Single and Double are "inexact" values - they use log tables to do the multiplication and division.
You might see a DOUBLE display as 4.5, but in reality it's stored as 4.4999999999.
It's that kind of issues that lead to major problems. All of a sudden SELECT CASE and IF THEN checks don't work.
We develop financial and payroll systems - so we are all too aware of the issues related to these two datatypes.
I agree that VARIANTS are terrible - but if the requirement for value in a variable exceeds a longword and accuracy is a must - then single and double cannot be considered.
-
Apr 15th, 2005, 07:05 AM
#10
Re: what variable should I use?
 Originally Posted by jeroen79
Floats lose precision at large values.
Code:
really: 990 + 990 = 1980
float: 99E1 + 99E1 = 19E2
990 + 990 = 1900
Imagine losing €80 after a deposit if your bank stores your account as a float.
That's why financial software packages would never use single or double datatype!
Single and double are designed (in the 1950's!) to shoot missles and rockets - and do the math in a floating-point processor chip...
-
Apr 15th, 2005, 07:05 AM
#11
Re: what variable should I use?
Never knew that. Cheers guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|