Magento Forum

   
getSubtotal - cut amount of decimals
 
marcfalk
Sr. Member
 
Total Posts:  87
Joined:  2008-11-22
 

Hey guys,

I’m using this piece of code to show the subtotal of the shopping cart in my header.phtml:

<? if(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal() > 0{ ?>
<?
=__(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal())?> 
<? } 
else { ?>

<? } ?>

It shows the subtotal of the cart, but with 6 decimals… how can I reduce this amount of decimals to only 2 ?

Thank you…

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

<? if(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal() > 0{ ?>
<?
=__(number_format(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(),2))?> 
<? } 
else { ?>

<? } ?>

That should take care of that smile. You can find more information regarding the number_format function here http://se.php.net/number-format.

 
Magento Community Magento Community
Magento Community
Magento Community
 
marcfalk
Sr. Member
 
Total Posts:  87
Joined:  2008-11-22
 
Bockbertil - 09 January 2009 03:05 AM

<? if(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal() > 0{ ?>
<?
=__(number_format(Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(),2))?> 
<? } 
else { ?>

<? } ?>

That should take care of that smile. You can find more information regarding the number_format function here http://se.php.net/number-format.

Thank you! Works like a charm wink

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top