we have amended our Magento 2.1 to use and store prices with 4 decimal places. But then used some JS to trim/round-up on the frontend to 2 decimal places.

However, on the email templates, the price is displaying with 4 decimal places e.g. £15.99000

Can I override the default email template to format the number to 2 decimal places (since the email doesn't allow JS)

I am currently looking at


And the price is currently being called like this...

<td class="item-price"> <?= /* @escapeNotVerified */ $block->getItemPrice($_item); ?> </td>

I tried changing the above to this instead...

<?php echo number_format($_item->getItemPrice(), 2); ?>

But that just seems to zero out the price, however it does read with 2 decimal places. So instead of it being £15.99 I just get £0.00

Where is my replacement code going wrong or am I even in the right place?


  • Is it possible you can include what you changed to get 4 dp working? Commented Jun 11, 2019 at 0:17
  • Not fully but basically we used this extension as a starting point to set the system to use 4DP github.com/lillik/magento2-price-decimal then applied some JS to trim off the extra zeros - there is a slight moment where 4DP shows on frontend when the page loads but we'll live with it Commented Jun 11, 2019 at 12:17

5 Answers 5


Mine seems to work well with using this code below.

<td class="item-price">
    <?= /* @escapeNotVerified */  $block->getItemPrice($_item->getOrderItem()) ?>

Hopefully this will fix your problem

  • Thanks for replying - it didn't work unfortunately - after making this change I actually could not checkout at all Commented Jun 11, 2019 at 11:38

That code should works

<td class="item-price">
    <?= /* @escapeNotVerified */  number_format($block->getItemPrice($_item), 2, '.', ''); ?>
  • Thanks for replying - this seems to wipe out the item details completely on the email. So where there would be the items listed, there is nothing Commented Jun 11, 2019 at 11:37
  • UPDATE: I am seeing this in debug.log when using the above [2019-06-11 12:29:56] main.CRITICAL: Warning: number_format() expects parameter 1 to be float, string given in /var/view_preprocessed/html/vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml on line 1 {"is_exception":false} [] Commented Jun 11, 2019 at 12:31

I think what's happening is getItemPrice is pulling through more than just a number



<?php echo number_format(preg_replace('/[^0-9.]/', '', $_item->getItemPrice()), 2); ?>

Potentially you will lose currency symbol though

  • Thanks Dominic but again that seems to remove the full items including product name etc from the email. And I see same error in debug.log Warning: number_format() expects parameter 1 to be float, Could/should it be converted to a float before trying to call it somehow? Thanks Commented Jun 11, 2019 at 14:50

I seem to have sorted it by using this instead...

Added new variable

$zx1 = $_item->getRowTotal();

Then just displayed that

<?php echo $zx1; ?>

Thanks to this question which pointed me in the right direction...

division of two variables is returning zero , in magento2 WHY?


I think when you use

<?php echo number_format($_item->getItemPrice(), 2); ?>

The code return " £15.99" not "15.99"

  • Yeah I don't think getItemPrice is a number/float so it can't convert it. Using getRowTotal works for me. It doesn't have the currency symbol but we are only single currency so I can just add one in manually. Commented Jun 13, 2019 at 8:19
  • @RichardLaws yeah, good look
    – heady9x
    Commented Jun 13, 2019 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.