SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2005
    0 Post(s)
    0 Thread(s)

    Question SQL Question - Column Datatype

    I've tried an integer column and a decimal column but whenever I try to input the figure '11.50' it automatically changes it to '12'.

    I'm also using the SUM() function on these columns so using varchar or something similar isn't an option.

    I cant see why my figure changes within an integer or decimal column.
    Turn My Text - íspuǝıɹɟ ʞooqǝɔɐɟ ɹnoʎ ǝzɐɯɐ puɐ ǝsnɟuoɔ

    Computer Game Cheats & Codes

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    The Netherlands
    153 Post(s)
    2 Thread(s)
    From the MySQL manual:

    When declaring a DECIMAL or NUMERIC column, the precision and scale can be (and usually is) specified; for example:

    salary DECIMAL(5,2)

    In this example, 5 is the precision and 2 is the scale. The precision represents the number of significant digits that are stored for values, and the scale represents the number of digits that can be stored following the decimal point. If the scale is 0, DECIMAL and NUMERIC values contain no decimal point or fractional part.
    So make sure that when you specify a column to be decimal that you specify the pricision and the scope.
    The number of digits before the decimal can be calculated by substracting scope from precion, and the number of digits after the decimal is the scope.

    So the maximum of a DECIMAL(5,2) is 999.99, for DECIMAL(6,2) it is 9999.99, etc


Posting Permissions

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