13

We can use following code for get $ mark and format money.

setlocale(LC_MONETARY, 'en_US.UTF-8');
$amount = money_format('%(#1n', $amount);

How to get euro symbol from php money_format?

Dinuka Thilanga
  • 4,220
  • 10
  • 56
  • 93

7 Answers7

14

i think this will work

setlocale(LC_MONETARY, 'nl_NL.UTF-8');
$amount = money_format('%(#1n', 20);
echo $amount;

Warning :-

This function has been DEPRECATED as of PHP 7.4.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged.

Rajeev Ranjan
  • 4,152
  • 3
  • 28
  • 41
  • But this code is not working for me. Because i have not local like nl_NL.UTF-8. Thanks for answering. – Dinuka Thilanga May 15 '13 at 09:28
  • Yes i know. Issue is my server. It hasn't any local named nll_NL.UTF-8 – Dinuka Thilanga May 15 '13 at 09:54
  • 1
    this prints "Eu" instead of "€" on my system – Jorre Jan 24 '14 at 17:22
  • Works fine, I know the thread is kinda old, but could you explain what $(#1n does roughly? – D. Schalla Feb 07 '14 at 11:42
  • 1
    @D.Schalla These are the Conversion characters.you can find the description with the example here http://in1.php.net/manual/en/function.money-format.php – Rajeev Ranjan Feb 07 '14 at 11:46
  • @Jorre you should add an money_format('%!(#1n', 20); this should remove the EU word. You have to add an ! – Jignesh Rawal Feb 28 '18 at 12:33
  • As this post is amongst the top results in search enines when looking for "how to format number to currency in php" it might be useful to update your answer as it is deprecated since php7.4. `$numberFormatter = new NumberFormatter( 'nl_BE', NumberFormatter::CURRENCY );` `$numberFormatter->formatCurrency($amount), 'EUR')` https://www.php.net/manual/en/numberformatter.formatcurrency.php – jnaklaas Sep 10 '20 at 16:57
  • 'money_format' is now deprecated. –  Nov 21 '21 at 23:29
3

Use this

setlocale(LC_MONETARY, 'nl_NL');
$amount = money_format('%(#1n', $amount);
Sudz
  • 4,268
  • 2
  • 17
  • 26
3
$price = 880000;
echo number_format($price, 2, ',', '.');

input => 880000

output => 880.000,00

Mahdi Bashirpour
  • 17,147
  • 12
  • 117
  • 144
2

A quite old thread but if some google here That worked even on a local MAMP

setlocale(LC_MONETARY, 'de_DE');
echo money_format('€ %!n', 1.620.56);

// € 1.620.56 
Metacowboy
  • 121
  • 2
  • 4
0

You can use the HTML entity

"&euro";

Directly in your code

$amount = money_format('%(#1n', $amount) .htmlentities('€');

EDIT

Or you can use the ! flag %(#!1n' so you code will looks like

$amount = money_format('%(#!1n', $amount) .htmlentities('€');

You can see the following post

Hope this would help

Community
  • 1
  • 1
Muhannad A.Alhariri
  • 3,702
  • 4
  • 30
  • 46
0

Finally a Italy locale worked for me.

$amount = '1600.00';
setlocale(LC_MONETARY, 'it_IT.UTF-8');
$amount = money_format('%.2n', $amount);
echo str_replace('Eu','€',$amount);
Himanshu Saini
  • 702
  • 11
  • 25
0

This is an old thread but I felt it worth sharing a relevant solution as the top answer doesn't provide an actual solution. I found this whilst searching for Spanish LC_monetary so if, like me, you end up here you know have an answer.

I use the following wrapped in a function with the advantage that it handles zeros nicely (see example in calculations ). I use this in my calculators for a slicker accounting layout. This example is Spain but you can use whichever Euro area you prefer:

setlocale(LC_MONETARY, "en_ES"); 
function C_S($iv) { 
    if(in_array($iv, array(' ','',0)) ){return'<i>&euro;</i>0.00';}
    else{return str_replace('EU','<i>&euro;</i>', money_format("%i", $iv));} 
} 

the italics are not necessary, I use them with css for alignment for finance style reports. Again, here for info.

to use:

echo C_S(1234);
Pete - iCalculator
  • 929
  • 1
  • 8
  • 12