+ Reply to Thread
Results 1 to 8 of 8

Thread: Limit discount percentage decimals

  1. #1
    Client
    Join Date
    Oct 2006
    Posts
    7
    Squirrelcart version
    v2.4.0

    Question Limit discount percentage decimals

    Where is the best location to limit the number of decimal points displayed with a discount?

    Right now the discount is displayed as 21.45% (with two decimal points of resolution) I want to display only 21%.

    Should I just modify the database table `Orders_Discounts` and change the field from
    `Savings_Percent` decimal(10,2) NOT NULL default '0.00',
    to
    `Savings_Percent` decimal(10,0) NOT NULL default '0',
    :
    ???

    Thanks!

  2. #2
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,829
    Squirrelcart version
    v3.3.7
    You can try that...I think it would work and shouldn't cause any harm. If it doesn't work let me know and I can give you some code to accomplish the same thing.

  3. #3
    Client
    Join Date
    Oct 2006
    Posts
    7
    Squirrelcart version
    v2.4.0
    Nope. Didnt do me any good. I suspect as all of the sales in this store front are based upon $ off rather than % off, the % is calculated before it is displayed, rather than storing the % in the database.(Please let me know if my guess is correct!)

    I can make the change, but if you would please point me at where that is being done it would save me a lot of time searching for it.

    Thanks!

  4. #4
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,829
    Squirrelcart version
    v3.3.7
    Yes, that is correct. The percentage is calculated. Here is how you can change it.

    1. If you haven't already, read this:
    http://www.squirrelcart.com/help/?Mo...Templates.html

    2. Copy the discounts_row.tpl.php template file into your custom theme folder.

    3. In that file, find this:
    PHP Code:
    <?=$Savings_Percent?>
    Replace it with this:
    PHP Code:
    <?=substr($Savings_Percent,0,2)?>
    4. Save the file

  5. #5
    Client
    Join Date
    Oct 2006
    Posts
    7
    Squirrelcart version
    v2.4.0
    !!!!

    I should have thought of that!!!

    Sorry for the bother!!!!

    Thank you for setting me straight!

    (wanders away slapping myself upside the head)

  6. #6
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,829
    Squirrelcart version
    v3.3.7
    Someone just asked me how to do this in newer versions. To do this in version 3.4.x (and most likely future versions as well), read on.

    You will need to know how to modify template files in Squirrelcart. If you are not familiar with that process, read this first:
    http://www.squirrelcart.com/help/?Mo...Templates.html

    First, you'll need to change the percentage here:
    example1.png

    To do that:
    1. Put a copy of squirrelcart/themes/squirrelcart/discounts_row.tpl.php in your custom theme folder

    2. Open that copy in an editor

    3. Find this:
    PHP Code:
    <?php print $Savings_Percent?>
    4. Change to:
    PHP Code:
    <?php print substr($Savings_Percent,0,2)?>
    5. Save the file

    Next, you'll need to change it here:
    example2.png

    6. Put a copy of squirrelcart/themes/squirrelcart/checkout_view.tpl.php in your custom theme folder

    7. Open it in an editor

    8. Follow steps 3, 4, and 5 above.

  7. #7
    Registered User
    Join Date
    Aug 2011
    Posts
    10
    Squirrelcart version
    not specified!

    round up or down

    will this change make the discount round to the nearest whole number, or round up or round down?

  8. #8
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,829
    Squirrelcart version
    v3.3.7
    No. This is stripping the decimal and everything after it. To round up, you would need:

    PHP Code:
    <?php print ceil($Savings_Percent)?>
    To round down:
    PHP Code:
    <?php print floor($Savings_Percent)?>
    To round to nearest whole number:
    PHP Code:
    <?php print round($Savings_Percent)?>

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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