Decimal of price and qty magento2.1
-
02-03-2021 - |
Question
I have a problem in my customer panel myorder tab. In my order i see price 12,125.0000 and QTY: 5.0000 how should i remove decimal from them? it is just in my order and methods that i used is like below:
$block->escapeHtml($_item->getRowTotalInclTax())
$_order->getShippingAmount();
$block->escapeHtml($_item->getQtyOrdered())
All of them has 4 decimal like this 0.0000 Any help?
Solution
Remove All Decimals :-
$rowTotal = (int)$_item->getRowTotalInclTax(); //12,125
$qtyOrdered = (int)$_item->getQtyOrdered(); //5
OTHER TIPS
You can use number_format function of PHP to achieve this.
Below is the basic syntax of number_format function:
number_format(number,decimals,decimalpoint,separator)
- number: Required. The number to be formatted. If no other parameters are set, the number will be formatted without decimals and with comma (,) as the thousands separator.
- decimals: Optional. Specifies how many decimals. If this parameter is set, the number will be formatted with a dot (.) as decimal point
- decimalpoint: Optional. Specifies what string to use for decimal point
- separator: Optional. Specifies what string to use for thousands separator. Only the first character of separator is used. For example, "xxx" will give the same output as "x"
For example: If you write
<?php
echo number_format("1000000", 2, ".", "");
?>
It will output like 1000000.00
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange