Closed (fixed)
Project:
Currency
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
11 Dec 2011 at 11:59 UTC
Updated:
24 Jul 2013 at 08:53 UTC
Jump to comment: Most recent file
Comments
Comment #1
amateescu commentedComment #2
xanoComment #3
amateescu commentedAnd the first brick has been laid :)
http://drupalcode.org/project/currency.git/commit/e559282
Comment #4
xanoAdded constructors and a locked property for currencies.
Comment #5
amateescu commentedDone: http://drupalcode.org/project/currency.git/commit/f4aaa9c
Comment #6
alan d. commentedI've just started a Android project for my brother that is going to take almost all of my spare time if this goes ahead, but I will try and contribute where possible.
Before jumping into the actual implementation, maybe a plan of attack should be formalized to what a core currency api should be trying to achieve. This would radically alter the internal implementation.
The number one decision to consider is how to handle various formats. I think that each currency rule defined should be defined against a locale, with US English as a base (This is wrong, as English English is the real en locale, but in Drupal en-US is default for en). While it seems that we should be inserting the correct symbols and formatting to each currency, but this is likely to cause confusion:
IE: 元123,4567.89
This does not look like a currency (this is Chinese yuan using Latin numbering) and could be possibly misread as 123 thousand rather than 1.23 million.
Or an example close to home, the Canadian dollar:
Canadian French: 123,45 $
Canadian English: $123.45
So for each currency, I would suggest having at least one rule for english and one for each locale of that currency. Just look at the Swiss franc in English, Swiss, German and you have 3 different formats.
Another thing that I discovered, all those months ago, was that it is extremely difficult to just provide a simple set of rules to handle the formatting of the currencies. Just check out localeconv() to see the required combinations, and even these do not cover the entire set of possibilities! A great resource is http://www.xencraft.com/resources/multi-currency.html
The solution that I used came down to a simple set of parameters that is mainly based off the currencies symbol and a format string.
The two core functions that used the currency object were, (these may or may not have been in the zip):
Two examples:
-₨ 1,23,45,678.90
-12,345,678.90 Pakistani rupees using the pattern -¤ #,##,##0.00 (notice the separator pattern)
(RM12,345,678.90)
-12,345,678.90 Malaysian ringgits using the pattern (¤#,##0.00)
Needs though testing, but from memory, it passed all of the manual tests that I tried.
Hopefully some food for thought, and this only covers the most basic formatting of a number!
Also, I hadn't even started to consider covering this, but electronic precision and Point of Sales precision would alter how a program should handle rounding... 1 cent in an Australian bank account is still used and significant, but in a shop, 5 cents is the lowest unit in circulation. Sign. It is a complex world out there, how much do we want to cover!?
Comment #7
xanoMost examples I have seen (and most of those you have given) only show differences between languages and not between currencies. However, the rounding issue may be relevant, but also very complex. Those rounding rules, do they only apply for a nation's own currency, or for foreign currencies used within that nation as well?
Next to that, I believe we may want to get rid of the thousands/grouping separator, because it's not a currency setting. Neither is the decimal separator, but that one is absolutely necessary to correctly display amounts and it's easier to implement
Comment #8
alan d. commentedI guess it is a question of keeping things simple or complex :)
In regards to currency formats per language, here are 3 Spanish variants from Latin America (parsed from the xml files from http://www.unicode.org/).
Argentine pesos: ¤-#,##0.00
Chilean pesos: -¤#,##0
Mexican pesos: (¤#,##0.00)
A couple of English ones:
Belize dollars: (¤#,##0.00)
Canadian dollars: -¤#,##0.00
Regarding precision. While I have only been to 30 countries, I have never been able to exchange minor units in any of these countries, or more specifically, you can not trade coins, only notes. However, all electronic exchanges are rounded to the nearest cent / minor unit, and I think that the official iso currency feed precision represents this digital representation. I think that the general rule of thumb is to never round until the final transaction tally is calculated and then rounding applies to the nearest precision from the official feeds.
Finally, the grouping separator is important in larger numbers, it instantly allows you to pick out the scale of large numbers accurately. Number formats usually correlate to currency formats, but not always. I do not think that PHP can handle the more complex grouping formats, aka these are still referred to as thousand separators even though this is a very western view :)
Comment #9
xanoCan you give me a link or a pointer to documentation about that representation format? (¤#,##0 etc)
So the Argentine peso uses ¤-#,##0.00, but how does one display the euro to an Argentine audience? Should the peso format be used for all currencies in an Argentine context? The same goes for rounding, sign position, etc: on how many contexts does either one of those properties depend? If every property depends on one context (currency/language/country), it may be a lot of work to implement all specific rules, but it won't be too complex. If those properties depend on more than one context, say a language AND a country, things become somewhat harder to administer for users and to maintain.
// Edit: if your example of Canadian dollars in Canadian English and Canadian French is correct, notation DOES depend on more than one context.
Comment #10
xanoLet's continue the display discussion in #1367862: Currency and amount display.
Comment #11
xanoComment #12
amateescu commentedComment #14
xanoComment #14.0
xanoKittens!