Data types: Should I always use double for numbers?

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
921
Office Version
  1. 365
Platform
  1. Windows
According to Professional Excel Development Second Edition pages 573-574, Excel internally use doubles. So should I always use doubles no matter what I do with numbers - if I need to use small numbers, like something between 1 and 200, I would choose data type byte for that, is it still better to a double there? Is the only reason not to use double that when you see double, you immediately think "oh, here we have big decimal number"?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
What I have always been taught is to choose the smallest possible data type for the job, as it is my understanding that choosing Double when something like Byte or Integer would do could potentially slow down your code, as using Double uses more memory.

I don't know if that excerpt you posted implies that even though I choose Integer, Excel is going to use Double anyway. It may be that it just uses the Double data type in calculations, but as for storing values to a variable, I think it still uses whatever data type you have declared the variable as.

Even if Excel *really* stored every numeric variables "behind the scenes" as Double too, it certainly does no harm to declare the variable with the appropriate Data Type. At the very least, it gives the programmer/user an idea as to the nature and size of the variable being used.
 
Upvote 0
Adding to Joe's comments...

If you're putting values onto worksheets they will become Doubles.
For counters in loops and other processing I use Long. You could use Integer but I read somewhere (forget the ref now) that Long Integer is processed faster than Integer -- something to do with internal defaults.
I also tend to manipulate currency values as Currency data type, because Currency is a decimal (Double is a binary) and therefore more accurate for decimals than Double.

Denis
 
Upvote 0

Forum statistics

Threads
1,225,502
Messages
6,185,349
Members
453,287
Latest member
Emeister

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top