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
:wave:
Printable View
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
:wave:
If you need fractional (floating-point) values - Single.
Otherwise, Long.
Integers offer a smaller range and steps of 1.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
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.
10,000,000,000 requires a Single data type.
What are the accuracy requirements in division and multiplication for the values you will be holding?Quote:
Originally Posted by dekelc
This might be your best choice - single and double are evil...
Quote:
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.
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 :D
Floats lose precision at large values.Imagine losing €80 after a deposit if your bank stores your account as a float.Code:really: 990 + 990 = 1980
float: 99E1 + 99E1 = 19E2
990 + 990 = 1900
Getting out of debt would be easy though.
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.
That's why financial software packages would never use single or double datatype!Quote:
Originally Posted by jeroen79
Single and double are designed (in the 1950's!) to shoot missles and rockets - and do the math in a floating-point processor chip...
Never knew that. Cheers guys. :thumb: