localising currency (help me out)

It seems there are no utilities around to localise currency (correct me if I’m wrong, I’m writing in C), so I’m having to write my own. Regardless of the system localisation, I want to be able to refer to a currency (for which I have the currency code) in a localised way.

Thus, what I’m looking for is for your 3-letter currency code, how do you refer to positive and negative numbers? For example, in AUD it would be “$1.25” and “−$1.25”.

Author: Danielle

Danielle is an Australian software engineer, computer scientist and feminist. She doesn't really work on GNOME any more (sadly). Opinions and writing are solely her own and so not represent her employer, the GNOME Foundation, or anyone else but herself.

18 thoughts on “localising currency (help me out)”

  1. @Michael: doesn’t that just localise into the system localisation? I want to be able to format a currency based on that currency code.

  2. @Denis: this is similar to what I’ve done. I have entries for the positive and negative representations. The number of decimal places is being provided to be along with the amount and the currency code, so I don’t need that bit.

  3. Sweden: SEK
    Iceland: ISK
    Regarding positive/negative, it’s the same as for AUD.

  4. @Danielle: To be entirely correct it should be “1,25 kr” and “-1,25 kr” since Sweden (not sure about Iceland here) uses “,” and not “.” as decimal point. Still, I don’t think most people would notice which decimal point was used, as long as the two are not mixed.

    For example, writing 1,000 kr would mean 1 kr, and not 1000 kr. For large numbers it is instead common to divide by blanks: 1 200 450,00 kr is “one million, two hundred thousand, four hundred and fifty kronor”

    Currency localization is obviously not an easy subject 😀

  5. Referring to Hannes’ comment, to add to the confusion, €1,000 means one thousand euro. As does €1000 and €1.000. Maybe not officially but it does when you ask a person in the street. On the other hand if it has two digits after the comma or point it is interpreted as cents. So €10,01 and €10.01 both mean ten euro and one cent to the average Euro-region person.

  6. I think the localization in the standard library (locale.h) already suffices, you can use nl_langinfo or localeconv to get the desired information. It is true that this will return values for the current locale but you can just: 1) save the current value for LC_MONETARY and LC_NUMERIC; 2) set it to the value you want; 3) call nl_langinfo or localeconv; 4) reset LC_MONETARY and LC_NUMERIC.
    I do not think you need any additional libraries.

  7. “locale -k LC_MONETARY”

    My guess is that things like:
    are what you want.

    int_p_cs_precedes 1 if the currency symbol precedes the internationally
    formatted monetary value for nonnegative values, 0 if
    it follows.

  8. In almost all cases formatting negative/positive representations of Money doesn’t depend on the Currency, it depends on the Locale of the person/system displaying the amount. If you want to display a list of multiple currencies, say in a currency converter, then you would format them all the same way for readability and to make it easier for the user to understand. Changing between . and , or symbol or sign position is just not good practise. You would need a very special use case for this to be otherwise.

    As you know, libc doesn’t know currency codes, only symbols. To get currency codes you will need libicu, or switch to KDE where KLocale / KCurrencyCode is fully aware of currency codes, multiple symbols, and the different formatting rules per locale 🙂 OK, KDE is not really an option, but if you’re looking for the data to write your own then ICU/CLDR or KDE will be a better source then crowd-sourcing. (Longer term, I’ll be switching KDE to an xml format for the currency data to make it easy to share).

  9. It’s probably just some weird accountant/tax form thing, but I’ve seen negative dollars represented as ($1.25). I only mention this because I can’t recall seeing formatting like -$1.25 anywhere — it’s generally written as a positive number and it’s expected the reader picks up the fact that it’s negative based on the context. I think I had a negative balance on a credit card when I accidentally overpaid it, and it used the -$1.25 representation, but I can’t remember for sure.

Comments are closed.

Creative Commons Attribution-ShareAlike 2.5 Australia
This work by Danielle Madeley is licensed under a Creative Commons Attribution-ShareAlike 2.5 Australia.