A question about the Decimal data type

  • I am confused about something when it comes to the decimal data type. Is the decimal point considered part of the precision? In other words how is 12345.67 defined? I have been told as decimal(8,3), decimal(8,2), decimal(7,3) and decimal(7,2).

    My guess would be decimal(8,2). I was hoping that I could get this cleared up once an for all.

    Thanks

  • meichner (8/1/2008)


    I am confused about something when it comes to the decimal data type. Is the decimal point considered part of the precision? In other words how is 12345.67 defined? I have been told as decimal(8,3), decimal(8,2), decimal(7,3) and decimal(7,2).

    My guess would be decimal(8,2). I was hoping that I could get this cleared up once an for all.

    Thanks

    BOL (Books Online) is your friend...

    http://msdn.microsoft.com/en-us/library/aa258832(SQL.80).aspx

    So: 12345.67 is decimal(7,2) 🙂

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Or rather - that's the minimum decimal size which could hold it.

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Thanks for the information and the link. I had an instructor which told us that the decimal point was part of the precision and another instructor who said it wasn't. I checked the net and was unable to find a definitive answer.

    Thanks again.

  • Simple test proves it...

    SELECT 1, CAST(1.23 AS DECIMAL(5,2))

    SELECT 2, CAST(12.34 AS DECIMAL(5,2))

    SELECT 3, CAST(123.45 AS DECIMAL(5,2))

    SELECT 4, CAST(1234.56 AS DECIMAL(5,2))

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks. I appreciate the help.

  • You bet. Thank you for the feedback.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply