SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist spoondevil's Avatar
    Join Date
    Jun 2001
    Location
    Harlow, Essex, UK
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Showing Entry to 2 Decimal Places

    I use the following query to extract prices from my database:
    SELECT sale_id, date_of_sale, date_format(date_of_sale, '%e %b') as date_of_sale2, category, brand, style, price, discount, total, extra_info FROM sales WHERE date_of_sale = curdate()
    and
    SELECT SUM(price) AS totalprice, SUM(discount) AS totaldiscount, SUM(total) AS totaltotal FROM sales WHERE date_of_sale = curdate()
    But... When the prices, discounts or totals are whole numbers, then they are stored as 35 not 35.00 Although it still works out the prices and maths correctly, the layout looks offish becuase some items have the decimal places, other don't.

    I would like these to automatically default to 2 decimal places. I'm not worried about whether this would be a auto feature on the database field [preferably], on the select query or the insert command.

    I store the prices, discounts & totals in varchar type fields

    Any help would be most grateful.

  2. #2
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,
    make sure your column type is set to float.
    Then modify (or create) your table to make it look, for example, like this:

    Code:
    FLOAT(5,2)


Bookmarks

Posting Permissions

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