Results 1 to 11 of 11

Thread: what variable should I use?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    what variable should I use?

    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

    Last edited by dekelc; Apr 15th, 2005 at 06:39 AM.
    Dekel C.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: what variable should I use?

    If you need fractional (floating-point) values - Single.
    Otherwise, Long.

  3. #3
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: what variable should I use?

    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
    Integers offer a smaller range and steps of 1.
    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.
    Last edited by jeroen79; Apr 15th, 2005 at 06:51 AM.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: what variable should I use?

    10,000,000,000 requires a Single data type.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: what variable should I use?

    Quote Originally Posted by dekelc
    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

    What are the accuracy requirements in division and multiplication for the values you will be holding?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: what variable should I use?

    This might be your best choice - single and double are evil...

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: what variable should I use?

    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

  8. #8
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: what variable should I use?

    Floats lose precision at large values.
    Code:
    really: 990  + 990  = 1980
    float:  99E1 + 99E1 = 19E2
            990  + 990  = 1900
    Imagine losing €80 after a deposit if your bank stores your account as a float.
    Getting out of debt would be easy though.

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: what variable should I use?

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: what variable should I use?

    Quote Originally Posted by jeroen79
    Floats lose precision at large values.
    Code:
    really: 990  + 990  = 1980
    float:  99E1 + 99E1 = 19E2
            990  + 990 =  1900
    Imagine losing €80 after a deposit if your bank stores your account as a float.
    That's why financial software packages would never use single or double datatype!

    Single and double are designed (in the 1950's!) to shoot missles and rockets - and do the math in a floating-point processor chip...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: what variable should I use?

    Never knew that. Cheers guys.

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