0

This question already has an answer here:

Below is my code for Google trusted Store. Currently it generates numeric values with four decimal places. For example, the value for this code: getGrandTotal(); ?> it returns value in the format 25.0000 Is there a way it could be forced to return a value for 2 decimal places i.e 25.00

Thanks,

<?php
$orderId = $this->getOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
$address = $order->getShippingAddress();
$backorder = false; // some backorder logic
$download = false; // some download logic
$shipDate = new Zend_Date(); // some logic to determine ship date
?>


<div id="gts-order" style="display:none;">


    <span id="gts-o-id"><?php echo $orderId; ?></span>
    <span id="gts-o-domain">www.example.com</span>
    <span id="gts-o-email"><?php echo htmlentities($customer->getEmail()); ?></span>
    <span id="gts-o-country"><?php echo htmlentities($address->getCountryId()); ?></span>
    <span id="gts-o-currency">USD</span>
    <span id="gts-o-total"><?php echo $order->getGrandTotal(); ?></span>
    <span id="gts-o-discounts">-<?php echo $order->getDiscountAmount(); ?></span>
    <span id="gts-o-shipping-total"><?php echo $order->getShippingAmount(); ?></span>
    <span id="gts-o-tax-total"><?php echo $order->getTaxAmount(); ?></span>
    <span id="gts-o-est-ship-date"><?php echo $shipDate->toString('yyyy-MM-dd'); ?></span>
    <span id="gts-o-has-preorder"><?php echo $backorder ? 'Y' : 'N'; ?></span>
    <span id="gts-o-has-digital"><?php echo $download ? 'Y' : 'N'; ?></span>



    <?php foreach ($order->getAllItems() as $item): ?>
        <span class="gts-item">
          <span class="gts-i-name"><?php echo htmlentities($item->getName()); ?></span>
          <span class="gts-i-price"><?php echo $item->getBasePrice(); ?></span>
          <span class="gts-i-quantity"><?php echo (int)$item->getQtyOrdered(); ?></span>
          <span class="gts-i-prodsearch-country">US</span>
          <span class="gts-i-prodsearch-language">en</span>
        </span>
    <?php endforeach; ?>


</div>

marked as duplicate by Matthéo Geoffray, 7ochem, Qaisar Satti, Marius Jan 28 '16 at 12:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

not sure if you figured this one out yet but you will need to round it down to 2 decimal points

<span id="gts-o-total"><?php echo (round($order->getGrandTotal(),2)); ?></span>
0

Please take a look at this post : https://magento.stackexchange.com/a/10089/33619
It is exactly the same problem as you have. To quote @Marius answer :

Try this:

Mage::helper('checkout')->getQuote()->getGrandTotal()

It will get you the grand total in this format 50.0000. If you want only 2 decimals use this:

number_format(Mage::helper('checkout')->getQuote()->getGrandTotal(), 2);

Not the answer you're looking for? Browse other questions tagged or ask your own question.