ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Simple Math plugin / PHP - round to two decimal places

December 21, 2010 1:19pm

Subscribe [1]
  • #1 / Dec 21, 2010 1:19pm

    Steve Garcia

    57 posts

    Follow up to this thread in the archive forums and thought it might be useful since we can’t post there any longer.

    I needed to get the final price from an item that was on sale with a percentage off. If you’re dealing with decimal points, the Simple Math plugin will not round or limit the results to two decimal points so you can use some PHP to get me the nice round number, here’s the full code I used:

    <?php
    $sale_price = {exp:simple_math calculate="{orig_price}-({orig_price}*({percent_off_amount}/100))"};
    echo number_format($sale_price, 2, '.', ',');
    ?>

    I believe Math Plus can handle this a little better, but had already purchased the Simple Math plugin so made do with what I had. Hope this helps.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases