Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

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