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

remove the decimal of product quantity in product view page
 
CaliforniaBiz
Jr. Member
 
Total Posts:  18
Joined:  2011-04-26
 

Hi,

I try to display product quantity in stock in product view page using this code:

QuantityOnly <?=Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?> available
.
However, there are 4 decimal places show up in the number.
Dose anyone know how to remove the 4 zeros?
Here is the screenshot.

Thanks!

SJ

Image Attachments
quantity_zeros.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
Peter Uhlich
Jr. Member
 
Total Posts:  7
Joined:  2009-02-20
 

You could use number_format:

<?php if($_product->getStockItem()): ?>QuantityOnly <?php echo number_format($_product->getStockItem()->getQty()); ?> available<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Peter Uhlich
Jr. Member
 
Total Posts:  7
Joined:  2009-02-20
 

.. or convert it to integer (if you not use floating numbers in your stock-management) .. here is an example including translations (you should use in your templates!):

<?php if($_product->getStockItem()): ?><?php echo $this->__('Quantity:');?> <?php echo $this->__('Only %s available',(int) $_product->getStockItem()->getQty()); ?> <?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
CaliforniaBiz
Jr. Member
 
Total Posts:  18
Joined:  2011-04-26
 

Thank you! It works perfect!

 
Magento Community Magento Community
Magento Community
Magento Community
 
cali75
Jr. Member
 
Total Posts:  13
Joined:  2011-07-23
 

Hi,

I notice the code dosen’t work with configurable products. I created the first configurable product today. The quantity shows “0” for this configurable product, even though there are 3 simple products inside this configurable product.

also how to control it to show up in a specific category product pages. I sell paintings and painting supplies on my site. I only want this quantity number to show up in painting product pages not in supplies category product pages.

thanks.

SJ

 
Magento Community Magento Community
Magento Community
Magento Community
 
mikevyas
Jr. Member
 
Total Posts:  8
Joined:  2012-12-09
usa
 

Thanks for sharing the code. And it actually works. From this Post I get good techniques so thanks for teaching me the right way.

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