-2

When we write an invoice, we have to respect the money format

For example :

  • in France, you will write 1000,00 €

  • In the USA, $ 1,000.00

I would like to know if it is handled by some PHP library ? especially the money symbol at the left or right.

Edit :

I have never been downvoted like this and i think my question wasn't that well asked. Sorry for that.

I already know different formatting functions in PHP and I understand that the formatter options should be selected for each country and their money format. Thou, i don't have the time to do that job.

My objective is to format any money values for all possible locales in the world without registering all those locales.

Maybe somebody wrote a class which can do the job but I didn't find it.

Btw I know it is difficult, I can for example talk of the example of the EUR.

In many contry they write EUR xxxxx. In some countries, it is written xxxx EUR.

Andresch Serj
  • 35,217
  • 15
  • 59
  • 101
P. Sohm
  • 2,842
  • 2
  • 44
  • 77
  • 3
    http://www.php.net/manual/en/function.money-format.php – Fluffeh Apr 03 '14 at 08:09
  • possible duplicate of [Best practice for working with currency values in PHP?](http://stackoverflow.com/questions/3819508/best-practice-for-working-with-currency-values-in-php) – Andresch Serj Apr 03 '14 at 08:09
  • fairly easy tool to use to find the answer to questions like this is a internet search engine called google. check it out https://www.google.com/search?q=currency+in+PHP – Andresch Serj Apr 03 '14 at 08:11
  • @AndreschSerj I disagree, money format give you the good format of the number but not the place of the money symbol etc. – P. Sohm Apr 03 '14 at 08:13
  • @AndreschSerj i don't think it is a duplicate of that question. I have no problem working with money. I just want to print it to the screen according of the rules in the country. – P. Sohm Apr 03 '14 at 08:36
  • Agreed, it's not a duplicate of that question (which doesn't mention formatting at all) – The Archetypal Paul Apr 03 '14 at 08:43

3 Answers3

3

Yep, by the intl module.

For currencies there is a NumberFormater class:

http://www.php.net/manual/en/numberformatter.formatcurrency.php

Andresch Serj
  • 35,217
  • 15
  • 59
  • 101
gontrollez
  • 6,372
  • 2
  • 28
  • 36
  • I didn't find that library before and it handle a large part of the problem : how to write the number. but it doesn't say where to place the money. – P. Sohm Apr 03 '14 at 08:34
  • Not sure what you mean by "where to place the money". You create an object passing the user locale, and it formats the currencies adding the symbol at the correct position. There are examples of this in the method documentation page linked. – gontrollez Apr 03 '14 at 09:03
0

http://ru2.php.net/number_format will help you.

You can simply setup it by yourself using number_format(). Save rule for each currency in db then apply on view regarding it's type.

user1954544
  • 1,619
  • 5
  • 26
  • 53
  • i find that function but it isn't good because you don't have a repository of the different money. I don't want to find the 180 money and find how to write them ;p – P. Sohm Apr 03 '14 at 08:14
  • You will HAVE to find 180 money anyway. Because you HAVE to know what currency is. Also you can use function as **gontrollez** said. But again before apply format you must know what currency is, and only then apply format. Yes, format mb it's a problem but I think you will have cases when you will change it manually. :Р – user1954544 Apr 03 '14 at 08:17
0

The basic PHP function money_format can handle your output quite well. If you need more, check out the Money PHP Library. IT is very powerfull.

From the Documentation:

<?php
$number = 1234.56;

// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
// USD 1,234.56

// Italian national format with 2 decimals`
setlocale(LC_MONETARY, 'it_IT');
echo money_format('%.2n', $number) . "\n";
// Eu 1.234,56

// Using a negative number
$number = -1234.5672;

// US national format, using () for negative numbers
// and 10 digits for left precision
setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
// ($        1,234.57)

// Similar format as above, adding the use of 2 digits of right
// precision and '*' as a fill character
echo money_format('%=*(#10.2n', $number) . "\n";
// ($********1,234.57)
Andresch Serj
  • 35,217
  • 15
  • 59
  • 101
  • it looks really powerfull, but I already saw it. I have to register all the money in the world if I want to write well – P. Sohm Apr 03 '14 at 08:29