MySQL storing numbers

Discussion in 'MySQL' started by J.P, May 17, 2006.

  1. #1
    Hi all,

    Not sure if this is possible so need to ask.

    I want to store numbers in a MySQL DB but in the format of 130.000 but the DB keeps knocking off the .000 as it's seeing the number as a decimal but I don't want it to, is there a way around this that you may know of?

    Ta

    JP
     
    J.P, May 17, 2006 IP
  2. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #2
    The only way you could do it is to store them as strings, though must admit I can't imagine a reason why you'd want to. If it's for display purposes just format the text in your server side code.
     
    dct, May 17, 2006 IP
  3. woodside

    woodside Peon

    Messages:
    182
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I normally use a double datatype when storing something like that.

    Use something like this when creating the table:

    CREATE TABLE `products` (
    `price` double(10,2) default NULL)

    -Erik
     
    woodside, May 17, 2006 IP
  4. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #4
    noppid, May 17, 2006 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes you can. What woodside says.

    decimal(15,4) is what I use for prices ex VAT with 4 decimals.

    1 Pound item is saved as 1.0000

    Copy Paste from PHPMyAdmin:

    products_price decimal(15,4) No 0.0000
     
    T0PS3O, May 17, 2006 IP
  6. swirl1980

    swirl1980 Peon

    Messages:
    53
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i don't understand y u'd wanna waste unecessary space in ya DB with trailing zero's. As DCT say's, store it as an int or woteva and use formatting on output!
     
    swirl1980, May 24, 2006 IP