Php money_format

I am trying to remove .00 at the end of the price

 function getMoney($mon) {
  setlocale(LC_MONETARY, 'en_US');
  return money_format('%.2n', $mon);
 }

Thanks,

+3
source share
5 answers

Try using this version of the money_format () function:

money_format('%.0n', $mon);

According to PHP documentation on money_format ( http://us.php.net/manual/en/function.money-format.php ), formatting the string "% .2n" will make the number appear with a decimal point and two decimal places to the right of the decimal point , regardless of what the cents are, and then format the number according to the format of the national currency in national currency.

"%.0n", . , , .00. .00, , $mon , , "% 0.2n".

+15

, , '%.2n', PHP, set_locale() Debian.

Debian, ?

+4

, PHP:

:

function getMoney($mon) {
  setlocale(LC_MONETARY, 'en_US');
  return money_format('%.0n', $mon);
 }
0

, , ? :

preg_replace("/\\.00^/", "", money_format('%.2n', $mon))
0

nickf is kinda and ben is wrong, your floating point variable may have a fractional part, but after formatting it can be rounded to 0 cents, so it should always be deleted after the fact. nickf code should be:
preg_replace('/\.00$/', '', money_format('%.2n', $mon))

0
source

Source: https://habr.com/ru/post/1719581/


All Articles