How to change Weight Attribute decimals Magento

There is no simple way to change the decimal numbers in the Weight Attribute in Magento.

And is not a specific solution either.

What can we do?

For example, we can force to all numeric attributes to show with 2 decimals.

Open the attributes.phtml located in:

app/design/frontend/YOUR THEME/template/catalog/product/view/

I changed this:

<?php echo $_helper->productAttribute($_product, strip_tags($_data['value']), $_data['code']) ?>
Code language: HTML, XML (xml)

To this:

<?php $_MyValue = $_data['value']; if (is_numeric($_MyValue)) { $_MyValue = round($_MyValue, 2); //round to 0.00 } ?> <?php echo $_helper->productAttribute($_product, strip_tags($_MyValue), $_data['code']) ?>
Code language: HTML, XML (xml)

What it does?

The code above adds a condition is_numeric and uses the round function to round it 😉

After it we just print again the attributes with our new value, in this case $my_data_value

About Ricard Torres

Senior Front-end Software Engineer at Netcentric, from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

9 comments

Leave a Reply

Add <code> Some Code </code> if you need to.

*
*