3
// code
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

#define SIZE 32
const char name[][SIZE] = {"en_US.utf8", "zh_CN.utf8", "zh_HK.utf8", "zh_TW.big5", "fr_BE.iso88591"};

int main(void)
{
    int count = sizeof(name) / SIZE;
    for (int i = 0; i < count; i++)
    {
        setlocale(LC_ALL, name[i]);
        const struct lconv *p = localeconv();
        printf("locale:[%s], currency symbol: [%s]\n", name[i], p->currency_symbol);
        printf("locale:[%s], international currency symbol: [%s]\n", name[i], p->int_curr_symbol); // why a tail space
    }

    return 0;
}

// output
locale:[en_US.utf8], currency symbol: [$]
locale:[en_US.utf8], international currency symbol: [USD ]
locale:[zh_CN.utf8], currency symbol: [?]
locale:[zh_CN.utf8], international currency symbol: [CNY ]
locale:[zh_HK.utf8], currency symbol: [HK$]
locale:[zh_HK.utf8], international currency symbol: [HKD ]
locale:[zh_TW.big5], currency symbol: [NT$]
locale:[zh_TW.big5], international currency symbol: [TWD ]
locale:[fr_BE.iso88591], currency symbol: [EUR]
locale:[fr_BE.iso88591], international currency symbol: [EUR ]

Why does each "international currency symbol" end with a space character? I am very confused with the result, who can give me some help?

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
ZhangXiongpang
  • 280
  • 2
  • 7
  • executed here it outputs another interesting space: `locale:[fr_BE.iso88591], currency symbol: [EUR ]` – Karoly Horvath Sep 25 '12 at 09:19
  • 3
    http://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_111.html `The value of int_curr_symbol should normally consist of a three-letter abbreviation determined by the international standard ISO 4217 Codes for the Representation of Currency and Funds, followed by a one-character separator (often a space).` Basically, just because. Would you write `USD100` or `USD 100`? – BoBTFish Sep 25 '12 at 09:26
  • Note this link to the EU publications office is a non-programming language source saying it is required. http://publications.europa.eu/code/en/en-370303.htm – BoBTFish Sep 25 '12 at 09:42
  • 1
    @BoBTFish: Actually, I might write `USD 100` (or the same with a unicode NBSP), in which case I have to strip the built-in separator. I'd stick with "just because" as the reason: any further explanation in terms of an example use case will just anger people who aren't using it that way ;-) – Steve Jessop Sep 25 '12 at 09:47
  • Also observe in that document you link to, that a space following the `EUR` is a nuisance in EU languages other than English, Irish, Latvian and Maltese. Because you'd have to strip it when the `EUR` is followed by punctuation: `Donnez-moi 30 EUR, s'il vous plaît`, not `Donnez-moi 30 EUR , s'il vous plaît`. So what the locale returns isn't as locale-aware as you might hope, because basically it assumes that `EUR 30` is the correct formulation which (according to that document) it normally isn't. – Steve Jessop Sep 25 '12 at 09:53

1 Answers1

2

Its just used as a separator. And the most common separator between two words is a space.

int_curr_symbol followed by the international currency symbol. This must be a 4-character string containing the international currency symbol as defined by the ISO 4217 standard (three characters) followed by a separator. Source: http://www.tin.org/bin/man.cgi?section=5&topic=LOCALE

read: http://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_111.html

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112