22

In PHP, is it possible to use money_format to display money without showing the currency or at least showing it in an abbreviated form?

Currently, I use:

$money = "1234.56";
setlocale("LC_ALL", "de_DE");
$money = money_format("%n", $money);

3 Answers 3

47

!

Seriously. that's the flag:

$money = money_format("%!n", $money);
2
  • 8
    Thanks, is there also a flag to use € instead of EUR?? Jul 5, 2011 at 18:33
  • $money = money_format("€ %!n", $money); works in my environments. Depends on server configuration unfortunately. Feb 18, 2015 at 21:18
5

try number_format($money)

http://php.net/manual/en/function.number-format.php

2
  • +1, This is really helpfull instead of money_format. Mar 4, 2014 at 13:49
  • Perfect for my use case. Thanks! Jun 25, 2015 at 16:00
0
// this if for Malaysia  , you can check according to your locality

$number = new NumberFormatter($locale = 'ms_MS.utf8', NumberFormatter::DECIMAL);
    echo $nmuber->format($amount)."\n"; ## 20,00,00,00,000
// if this give error 
Class 'NumberFormatter' not found
// for this  you can do  you can do a
apt-get install php7.0-intl

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.