Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    6

    Unanswered: MySQL Data type for percent

    I am trying to set up 2 columns.
    One is for Price in US dollars.
    Two is for the percent markup (of the above Price).

    Examples:
    $100.00 for Price
    10.5% for percent markup

    So the resulting purchase price would be Price plus percent markup.
    In this case it would be $110.50

    I understand that DECIMAL 4,2 would be the approprate data type for the Price column.

    What would be appropriate data type for the percent markup column?

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    Use decimal for that as well. You would write 10.5% as .105
    you would need to use decimal (4,3) for that as you might need to represent a 100% or more markup.

    Also you might find you need to use the round() function when doing your calculations to get the right number of decimals for your price.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    the largest number that decimal(4,2) can hold is 99.99

    the largest number that decimal(4,3) can hold is 9.999
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Mar 2004
    Posts
    480
    Well I was thinking that he would represent 10% as .1 and 100% as 1.00, the ,3 would be needed to represent the third digit of 1/2 percent as .005

    Too many baseball stats for me I guess, since I'm used to representing a '300' batting average as .300
    Last edited by guelphdad; 05-09-04 at 02:24.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yeah, i realize that, dave, it's just that he said he wanted to represent his price as decimal(4,2), and i concluded that he assumed this was 4 digits left of the decimal point and two to the right, so i thought i would clarify for his sake

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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