SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Working out percentages

    Hi Guys,

    i don;t know if this is at all possible but say i have 2 prices in mysql:

    1.99 and 2.99

    is it possible to work out the % you have saved from the old to the new price?

    i.e you have saved 11%

    thanks for any info guys

    Graham

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The general formula is:
    Code:
    100 - new price / old price * 100
    In PHP:
    Code:
    $oldPrice = 2.99;
    $newPrice = 1.99;
    echo round(100 - $newPrice/$oldPrice * 100) . "%"; // will print 33%
    In SQL:
    Code:
    select round(100 - new_price/old_price * 100) as price from prices
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why wouldnt that be possible


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
  •