Single vs Double - precision floating point number

Last post 03-06-2006 10:43 AM by Caddre. 2 replies.

Sort Posts:

  • Single vs Double - precision floating point number

    03-02-2006, 11:58 AM

    Hello,

    I have a value, EdgeChangeThreshold which is the minimum change in an edge (yesterday vs today) for a stock details to be displayed on the page

     This value will be entered by the users. The calculated formula for the difference in edge is a basis point (abs(previous edge )- abs(current edge))/previous edge (display format 0.0000%) that will be displayed .

    In order to validate the value entered based on which I can return the security details, should I use decimal or single or double(System.Struct)? What is the difference?

    Thanks in advance!!!

    dotnetnew123

     

  • Re: Single vs Double - precision floating point number

    03-02-2006, 2:15 PM
    From this article (a good read):

    Fixed-point Type

    The System.Decimal type is a kind of hybrid between an integer and a floating-point number. It is a 128-bit (16-byte) data structure that can exactly represent values ranging from -79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335, with up to 29 significant digits. The C# name for this type is decimal. In Visual Basic it's Decimal.

    The Decimal type is a structure that consists of a 1-bit sign, a 96-bit integer, and a scaling factor that specifies where to put the decimal point. The scaling factor is a number from 0 to 28, representing the number 10 raised to that power, which is used to divide the 96-bit integer. So, if the integer number is 12 and the scaling factor is 1, then the value represented is 12 divided by 101, or 1.2.

    The beauty of this type is that it can exactly represent decimal values—something that's especially important when working with currency values. Whereas floating-point numbers are approximations (albeit very close approximations), decimal values are exact. For example, if you use a floating-point type to add and subtract currency values, eventually you'll end up with a number that has more than just two decimal places. You might end up with 349.999997, for example.

    If you use a Decimal type to add currency values, you'll always end up with two decimal places.


    Darrell Norton, MVP
    Darrell Norton's Blog


    Please mark this post as answered if it helped you!
  • Re: Single vs Double - precision floating point number

    03-06-2006, 10:43 AM
    • Loading...
    • Caddre
    • Joined on 06-23-2003, 9:53 AM
    • Indy
    • Posts 5,308

    I would use Decimal because Basis point is just fancy way for decimal points in different places, ten basis points movement is the stock moved ten cents in either direction. So 100 basis points in layman language is 100 cents which is one dollar, a few currencies like yen minor difference.   In SQL Server if you are doing calculations you may need Float because eighty percent of the quantitative functions like LOG are in Float but when calculating money it is good practice to use either Numeric or Decimal in your creat table statement so you can control precision and scale. 

    BTW the NYSE did not change to basis points until everybody was required to change.  Hope this helps.

    Kind regards,
    Gift Peddie
Page 1 of 1 (3 items)