Dinuka Thilanga
Dinuka Thilanga

Reputation: 4330

PHP money_format for EURO

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?

Upvotes: 13

Views: 38117

Answers (7)

Rajeev Ranjan
Rajeev Ranjan

Reputation: 4142

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.

Upvotes: 14

Mahdi Bashirpour
Mahdi Bashirpour

Reputation: 18833

$price = 880000;
echo number_format($price, 2, ',', '.');

input => 880000

output => 880.000,00

Upvotes: 3

Pete - iCalculator
Pete - iCalculator

Reputation: 929

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);

Upvotes: 0

Metacowboy
Metacowboy

Reputation: 121

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 

Upvotes: 2

Himanshu Saini
Himanshu Saini

Reputation: 812

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','&euro;',$amount);

Upvotes: 0

Muhannad A.Alhariri
Muhannad A.Alhariri

Reputation: 3912

You can use the HTML entity

"&euro";

Directly in your code

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

EDIT

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

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

You can see the following post

Hope this would help

Upvotes: 0

Sudz
Sudz

Reputation: 4308

Use this

setlocale(LC_MONETARY, 'nl_NL');
$amount = money_format('%(#1n', $amount);

Upvotes: 3

Related Questions