Use money format in php format and delete numbers after decimal point for GBP

I want to format some of the numbers from my analytics into a currency using the money format in GB format, but it’s not necessary to be so precise for the toolbar, so I want to remove the penny (numbers after the decimal place) and the round helps with css layout, How can I do it? Rounding up or down to the nearest pound will be fine.

My code is as follows:

//set locale for currency
setlocale(LC_MONETARY, 'en_GB');

$sales = '8932.83';

echo utf8_encode(money_format('%n', $sales));

This result: £ 8,932.83

How can I get around this in order to withdraw just 8,932 pounds without any digits after the decimal point.

I want to use the currency format, because sometimes the indicator is negative, and in this case money_format returns a number, for example - £ 8,932.83, which is preferable to £ -8,932 (the pound and the negative symbol are wrong), which happened when I formatted using number_format as follows:

echo '£'.number_format($sales, 0, '', ',');
+4
source share
1 answer

Do you want to round it or get rid of decimals?

To round it up, which would be 8933:

echo utf8_encode(money_format('%.0n', $sales));

To get rid of decimals, you can use the floor (which is rounded down):

echo utf8_encode(money_format('%.0n', floor($sales)));
+9
source

All Articles