Search code examples
phpmagentoattributeszero

Remove extra zeros from value of custom attribute "ship_cost" in magento 1.9.2.3


I have a Custom Product Attribute named as 'ship_cost' with an input type 'text field'. While putting a value on back-end, it automatically adds four extra zeros after the decimal point.

I want this price in 'Rs. 45.00' format but currently it is showing as 'Rs. 45.0000'.

I have not worked with Magento for a long time, basically, I am a newbie.


Solution

  • There's a few ways to do this.

    A simple fix would be to just use the number_format() function:

    <?php 
        $_product = $this->getProduct();
        $prodShipCost = $_product->getData('ship_cost'); // Or however you want to get the attribute values
        $priceFormatted = number_format($prodShipCost, 2, '.', '');
        echo $priceFormatted;
    ?>