# Thread: Do you use Decimal, single, or double?

1. ## Do you use Decimal, single, or double?

Let's say you know the value is always going to be smaller, like below 32,000
Do you use Decimal, single, or double?
I almost prefer Decimal just for readability, for some weird reason.

2. ## Re: Do you use Decimal, single, or double?

Is that 32 thousand, or 32 with three decimal digits.
If the numbers don't require decimal places, I would generally use Integer (32-bit).
If I don't need a lot of precision, say the altitude of an aircraft in meters, or the heading in degrees, then I would use Single.
For something where I want more resolution, like Latitude or Longitiude, then I would use Double.
Doubles and Singles are generally about the same speed in calculations, but if doing a lot of math functions, then I would use Doubles for that as well.

Using Decimal is slower and bulkier than the other types, and I haven't had a need to use it as I don't usually do financial or data base storage that may prefer the Decimal type.

3. ## Re: Do you use Decimal, single, or double?

Accuracy vs performance:
https://docs.microsoft.com/en-us/dot...ric-data-types
"The Double data type is faster and requires less memory, but it is subject to rounding errors. The Decimal data type retains complete accuracy to 28 decimal places."

i.e., don't use double or single if you can't stomach any rounding errors.

4. ## Re: Do you use Decimal, single, or double?

i usually use double. only in some cases where i know that a single precision is sufficient and memory might be an issue, i use singles. i almost never use decimal.

5. ## Re: Do you use Decimal, single, or double?

For integral numbers I use int or long depending on the size of the value.

For fractional values, I use Single only if the method I'm passing to requires a Single type, otherwise I use Doubles exclusively unless I need to ensure exact precision, then I'll use a Decimal.

6. ## Re: Do you use Decimal, single, or double?

Assuming fractional values when dealing with finances(money) I use Decimal.

7. ## Re: Do you use Decimal, single, or double?

Originally Posted by kebo
For integral numbers I use int or long depending on the size of the value.

For fractional values, I use Single only if the method I'm passing to requires a Single type, otherwise I use Doubles exclusively unless I need to ensure exact precision, then I'll use a Decimal.
Indeed, Integer and Double should be the default for whole and real numbers respectively, because these are the types that modern CPUs handle most efficiently. That's the reason that numeric literals without a decimal point and with are implicitly those types respectively unless you explicitly force them to another type using a suffix.

For whole numbers, use Long or BigInteger as required for values with a larger range and only use Short or Byte when you explicitly need to use the data as those types, e.g. the loop counter in a For loop should be type Integer, even for very small ranges, unless you explicitly need something else.

For real numbers, use Single only in specific cases where it is required. Both Single and Double are susceptible to round-off errors so, in cases where that is an issue, use Decimal instead. It's not an issue as often as people think it is though. Producing a single value with a round-off error generally doesn't really matter in cases where you should only care about the first one or two decimal places anyway. It's only really if you need to do something like sum a lot of values that you need the accuracy that Decimal provides.

The one other scenario where you should consider using Short or Single is when memory is a genuine issue, e.g. an embedded system. For the vast majority of PC and even phone applications, the tiny bit of memory you save is simply insignificant.

8. ## Re: Do you use Decimal, single, or double?

Short answer. Decimal for finance. Double for science.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•