Results 1 to 8 of 8

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

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2014
    Posts
    268

    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. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,250

    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.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  3. #3
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    679

    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.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  4. #4
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,321

    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. #5
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,737

    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.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,334

    Re: Do you use Decimal, single, or double?

    Assuming fractional values when dealing with finances(money) I use Decimal.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,041

    Re: Do you use Decimal, single, or double?

    Quote Originally Posted by kebo View Post
    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. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,907

    Re: Do you use Decimal, single, or double?

    Short answer. Decimal for finance. Double for science.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

Posting Permissions

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



Click Here to Expand Forum to Full Width