Questions tagged [money-format]

money_format is a PHP function that formats a number as a currency string.

money_format is a PHP function that formats a number as a currency string.

string money_format ( string $format , float $number )

It can also be combined with .

Examples

echo money_format('%.2n', 33); // Returns 33.00
echo money_format('%i', 33);   // Returns 33.00

setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', 33);   // Returns USD 33.00

References

121 questions
45
votes
15 answers

Alternative to money_format() function

I am trying to use the money_format() function in PHP, but it gives the following error: Fatal error: Call to undefined function money_format() Searches about this error reveal that the function money_format() is only defined if the system has…
Pramod Kumar Sharma
  • 7,851
  • 5
  • 28
  • 53
37
votes
22 answers

How to display Currency in Indian Numbering Format in PHP?

I have a question about formatting the Rupee currency (Indian Rupee - INR). For example, numbers here are represented as: 1 10 100 1,000 10,000 1,00,000 10,00,000 1,00,00,000 10,00,00,000 Refer Indian Numbering System I have to do with it PHP. I…
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
23
votes
1 answer

If dealing with money in a float is bad, then why does money_format() do it?

I've been waffling on how to deal with currency display and math in PHP, and for a long time have been storing it in MySQL using the DECIMAL type, and using money_format() to format it for display on the web page. However, today I looked at the…
Andrew
  • 5,095
  • 6
  • 42
  • 48
22
votes
3 answers

PHP show money_format without currency text

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);
Frank Vilea
  • 8,323
  • 20
  • 65
  • 86
17
votes
7 answers

PHP money_format(); £ sign not GBP

I cannot work out how to get the currency symbol? At the moment I am using setlocale(LC_MONETARY, 'en_GB'); money_format('%i', 1000); Which give me the output GBP1,000 But I want £1,000 I have checked out the PHP manual but it isn't that…
Max Rose-Collins
  • 1,904
  • 5
  • 26
  • 45
13
votes
7 answers

PHP: Converting dollars to cents

As input, I want to accept any of the following: "$12.33", "14.92", "$13", "17", "14.00001". As output, I want 1233, 1492, 1300, 1700 and 1400 respectively. This is apparently not as easy as it looks:
Mala
  • 14,178
  • 25
  • 88
  • 119
13
votes
7 answers

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?
Dinuka Thilanga
  • 4,220
  • 10
  • 56
  • 93
11
votes
5 answers

PHP intval vs floor

Is there any difference between floor() and intval()? Though both returns the same results, is there any issue with regard to performance? Which of the two is faster? Which is the right php function to use if I just want to return the whole value…
basagabi
  • 4,900
  • 6
  • 38
  • 84
10
votes
2 answers

PHP money format with spaces

I am wondering if there is a way to separate thousands with space character. For example: $number = 21234.56; setlocale(LC_ALL, 'pl_PL.utf8'); echo money_format('%i', $number); is giving me: 21.234,56 PLN And I want: 21 234,56 PLN I don't want to…
Cleankod
  • 2,220
  • 5
  • 32
  • 52
9
votes
1 answer

PHP money_format

I'm using on money_format with the first parameter being '%n' to include the dollar sign, and I have the locale set to en_US but it still doesn't include it. Why?
user504974
7
votes
2 answers

Defining cross-platform money_format function (Linux and Windows)

I have read that money_format is not available on windows, and on some Linux distributions (i.e. BSD 4.11 variants). But I want to write cross-platform library using normal function, when available and using this workaround when not, so my library…
Karol
  • 7,803
  • 9
  • 49
  • 67
7
votes
2 answers

yii2 - how to set currency decimal value

I want my currency to ignore decimal value, so far I have this: main.php: 'formatter' => [ 'class' => 'yii\i18n\Formatter', 'thousandSeparator' => '.', 'decimalSeparator' => ',', 'currencyCode' => '€', ], view: [ 'attribute' =>…
rob180
  • 901
  • 1
  • 9
  • 29
7
votes
2 answers

Use php money format and remove the numbers after the decimal place for GBP

I want to format some numbers from my analytics into currency using the GB money format but as its for a dashboard and doesn't need to be that precise so I want to remove the pence (numbers after the decimal place) and round it which helps with the…
Ben Paton
  • 1,432
  • 9
  • 35
  • 59
6
votes
4 answers

PHP Money Format in Indian Currency?

For example $num='7,57,800'; How can I display the value of $number as 7.57 Lakhs?
5
votes
8 answers

Money Format Number VB.NET

I'm trying to convert a mathematical result of money format example: Dim num1 As Integer = 2000 Dim num2 As Integer = 500 msgbox(cDbl(num1 + num2)) It only returns 2500, which I need to return my 2,500.00 if anyone has any idea how I would be very…
John Nuñez
  • 1,780
  • 13
  • 35
  • 51
1
2 3
8 9