Italiano
Italiano

Reputation: 55

money_format php 2 decimals without currency symbol

I have this function:

money_format("%!n", $number);

This will output: 2200

How I have to edit my function to have: 2200.00 Thanks for the help!

Upvotes: 0

Views: 2590

Answers (2)

gidomanders
gidomanders

Reputation: 465

in money format, use ".{numberOfDigits}" for the amount of digits after the separator:

money_format("%!.2n", $number);

or use number format, because you don't want the currency symbol anyway:

number_format($number, 2);

Upvotes: 2

Hanky Panky
Hanky Panky

Reputation: 46900

$number=2200;
setlocale(LC_MONETARY, 'en_US');
echo money_format("%.2n", $number);    //2200.00

Fiddle

PHP Manual for formats

Upvotes: 2

Related Questions