All this is copied from:
http://www.vanwijk.com/-%3D%20Bookz%20%3D-/C++%20Builder%20Unleashed/h
tm/ch03.htm
<quote>
The format used in this case is global to the system. You can change
these settings
by working with a series of global variables found in SYSUTILS.HPP:
extern System::AnsiString CurrencyString;
extern unsigned char CurrencyFormat;
extern unsigned char NegCurrFormat;
extern char ThousandSeparator;
extern char DecimalSeparator;
extern unsigned char CurrencyDecimals;
extern char DateSeparator;
extern System::AnsiString ShortDateFormat;
extern System::AnsiString LongDateFormat;
extern char TimeSeparator;
extern System::AnsiString TimeAMString;
extern System::AnsiString TimePMString;
extern System::AnsiString ShortTimeFormat;
extern System::AnsiString LongTimeFormat;
extern System::AnsiString ShortMonthNames[12];
extern System::AnsiString LongMonthNames[12];
extern System::AnsiString ShortDayNames[7];
extern System::AnsiString LongDayNames[7];
On my system, these values are preset as follows:
CurrencyString: $
CurrencyFormat: 0
NegCurrFormat: 0
ThousandSeparator: ,
DecimalSeparator: .
CurrencyDecimals: 2
DateSeparator: /
ShortDateFormat: M/d/yy
LongDateFormat: dddd, MMMM dd, yyyy
TimeSeparator: :
TimeAMString: AM
TimePMString: PM
ShortTimeFormat: h:mm AMPM
LongTimeFormat: h:mm:ss AMPM
ShortMonthNames: Jan
ShortMonthNames: Feb
ShortMonthNames: Mar
ShortMonthNames: Apr
ShortMonthNames: May
ShortMonthNames: Jun
ShortMonthNames: Jul
ShortMonthNames: Aug
ShortMonthNames: Sep
ShortMonthNames: Oct
ShortMonthNames: Nov
ShortMonthNames: Dec
LongMonthNames: January
LongMonthNames: February
LongMonthNames: March
LongMonthNames: April
LongMonthNames: May
LongMonthNames: June
LongMonthNames: July
LongMonthNames: August
LongMonthNames: September
LongMonthNames: October
LongMonthNames: November
LongMonthNames: December
ShortDayNames: Sun
ShortDayNames: Mon
ShortDayNames: Tue
ShortDayNames: Wed
ShortDayNames: Thu
ShortDayNames: Fri
ShortDayNames: Sat
LongDayNames: Sunday
LongDayNames: Monday
LongDayNames: Tuesday
LongDayNames: Wednesday
LongDayNames: Thursday
LongDayNames: Friday
LongDayNames: Saturday
For instance, the following code changes the nature of the current
ShortDateFormatString:
void __fastcall TForm1::SetShortDateFormattoMMMMDDDDYYYY1Click(TObject
*Sender)
{
RichEdit1->Text = Now();
ShortDateFormat = "MMMM/DDDD/YYYY";
RichEdit1->Lines->Add(Now());
}
The text displayed by calling this function is as follows:
1/7/97 1:30:21 PM
January/Tuesday/1997 1:30:21 PM
The first block of text shows the default behavior, and the second
block
shows what happened after I made a few subtle changes to the system.
The system initializes the date and time strings to the choices you
make
in Windows. You can see the current Windows settings by calling
GetLocaleInfo. Changes you make are written to the system registry if
you
send a WM_INICHANGE message to your own nonconsole mode application.
</quote>
Best regards,
Vladimir Stefanovic
<Roger Warren> wrote in message
news:41b9992f$1...@newsgroups.borland.com...
> Hi,
>
> How can I obtain the currency symbol for the currenct
locale/regional
> setting? I have tried using:
>
> ...
> struct lconv ll;
> struct lconv *conv = ≪
> conv = localeconv();
> printf("Currency symbol: %s\n", conv->currency_symbol);
> ...
>
> But it doesn't seem to produce anything.
>
> Any help would be appreciated. Thanks.
>
> How can I obtain the currency symbol for the currenct locale/regional
> setting? I have tried using:
>
> ...
> struct lconv ll;
> struct lconv *conv = ≪
> conv = localeconv();
> printf("Currency symbol: %s\n", conv->currency_symbol);
> ...
>
> But it doesn't seem to produce anything.
Questions about localization issues are always interesting, and I am
always surprised at what I see while experimenting ...
I hacked together the following:
#include <locale>
#include <iostream>
#include <ostream>
void dump_currency_symbol(char const *locname)
{
try
{
typedef std::moneypunct<char> moneyp_type;
std::cout << std::use_facet<moneyp_type>(std::locale(locname))
.curr_symbol() << '\n';
}
catch (std::exception const &e)
{
std::cerr << e.what() << '\n';
}
}
int main()
{
dump_currency_symbol("");
dump_currency_symbol("de_DE");
dump_currency_symbol("de_CH");
dump_currency_symbol("en_US.iso8859-1");
dump_currency_symbol("de_CH.iso8859-1");
}
On my Linux box, the LANG environment variable defaults to en_US (that
was actually the first surprise ... I must have set it like that
because some porgram that I probably haven't been using for month
required it). If I run the program, as compiled by the latest gcc
(3.4.3), I get
$
EUR
Fr.
locale::facet::_S_create_c_locale name not valid
locale::facet::_S_create_c_locale name not valid
When I change LANG to de_CH, I get
Fr.
EUR
Fr.
locale::facet::_S_create_c_locale name not valid
locale::facet::_S_create_c_locale name not valid
, i.e. I can use std::locale("") to get a locale object the reflects
the current setting of the LANG environment variable.
The exceptions on the last two attempts are no surprise, though. The
names used here are my guesses at what locales are called on Windows;
don't bet your form on them. If anybody can tell me what the
equivalent of the Linux command
locale -a
(i.e. list all available locale names) is on Windows, I'd be very glad.
The real surprise came when I through C++BuilderX at the program to
run it on Windows. Whatever tampering I do with LANG and LC_MONETARY,
I always get
SFr.
SFr.
SFr.
SFr.
SFr.
which is good news for you, because German/Switzerland is my Windows
setting.
And when I use gcc (3.1.1) on Windows. Again, no matter what I set
LANG and LC_MONETARY to, I always get five empty lines ...
FloatToStrF(0.0, ffCurrency , 6, 2).SubString(1,1);
<Roger Warren> wrote in message news:41b9992f$1...@newsgroups.borland.com...
> Hi,
>
> How can I obtain the currency symbol for the currenct locale/regional
> setting? I have tried using:
>
> ...
> struct lconv ll;
> struct lconv *conv = ≪
> conv = localeconv();
> printf("Currency symbol: %s\n", conv->currency_symbol);
> ...
>
> But it doesn't seem to produce anything.
>
> dump_currency_symbol("en_US.iso8859-1");
> dump_currency_symbol("de_CH.iso8859-1");
>
>The exceptions on the last two attempts are no surprise, though. The
>names used here are my guesses at what locales are called on Windows;
>don't bet your form on them. If anybody can tell me what the
>equivalent of the Linux command
>
>locale -a
>
>(i.e. list all available locale names) is on Windows, I'd be very glad.
Does EnumSystemLocales() help any?
>#include <locale>
>#include <iostream>
>#include <ostream>
>
>void dump_currency_symbol(char const *locname)
>{
> try
> {
> typedef std::moneypunct<char> moneyp_type;
std::cout<<locname<<std::use_facet<moneyp_type>(std::locale(locname)).curr_symbol()<<'\n';
> }
> catch (std::exception const &e)
> {
> std::cerr << e.what() << '\n';
> }
>}
BOOL CALLBACK EnumLocalesProc( LPTSTR lpLocaleString )
{
dump_currency_symbol(lpLocaleString);
return TRUE;
}
>int main()
>{
dump_currency_symbol("");
EnumSystemLocales( EnumLocalesProc );
>}
This looks like a good start, but it doesn't seem to work.
> BOOL CALLBACK EnumLocalesProc( LPTSTR lpLocaleString )
> {
> dump_currency_symbol(lpLocaleString);
lpLocaleString is not a locale name, but a stringized numerical value,
e.g.: 00000403.
Now I'm not sure that these values can't be used to identify locale
names. They are certainly not the way I'm used to.
> EnumSystemLocales( EnumLocalesProc );
BTW: EnumSystemLocales() takes two arguments. The second one is used
to distinguish between supported and installed locales.
>Bob Gonder <no...@notmindspring.invalid> writes:
>
>This looks like a good start, but it doesn't seem to work.
Ok, here you go.
For fun, you might try the commented LOCALE_SNATIVELANGNAME
Win32 Console App in C
#include <stdio.h>
#include <windows.h>
#define hexs(c) (0x0f & (c>'9'? c-('A'-10) : c) )
static char* _stdcall unhex( BYTE*dest, char*src, DWORD len)
{ while( len-- )
{ *dest = (hexs(src[0])<<4) | hexs(src[1]);
++dest;
++src;
++src;
};
return src;
}
void dump_currency_symbol(char const *locname)
{ CHAR buffer[128];
WORD loc;
unhex( &loc, &locname[4], 2 );
if( GetLocaleInfo( loc,
LOCALE_SENGLANGUAGE/*LOCALE_SNATIVELANGNAME*/,
buffer,128 ) )
printf("\r\nLocale: %s %s", locname, buffer );
if( GetLocaleInfo( loc, LOCALE_SCURRENCY, buffer,128 ) )
printf("\t Curency: %s", buffer );
if( GetCurrencyFormat( loc, LOCALE_NOUSEROVERRIDE,
"-12345.78", NULL, buffer,128) )
printf("\t %s", buffer );
}
BOOL CALLBACK EnumLocalesProc( LPTSTR lpLocaleString )
{
dump_currency_symbol(lpLocaleString);
return TRUE;
}
int main(void)
{
dump_currency_symbol("00000000");
EnumSystemLocales( EnumLocalesProc,LCID_INSTALLED );
// EnumSystemLocales( EnumLocalesProc,LCID_SUPPORTED );
return 0;
}
C:\TEST>locale
Locale: 00000000 English Curency: $ ($12,345.78)
Locale: 00000404 Chinese Curency: NT$ -NT$12,345.78
Locale: 00000408 Chinese Curency: úñ úñ-12,345.78
Locale: 0000040c Chinese Curency: HK$ (HK$12,345.78)
Locale: 00000410 Chinese Curency: $ ($12,345.78)
Locale: 00000414 Chinese Curency: P (P12,345.78)
Locale: 00000804 Greek Curency: Ç -12.345,78 Ç
Locale: 00000c04 French Curency: Ç -12á345,78 Ç
Locale: 00000c0c French Curency: $ (12á345,78 $)
Locale: 00001004 Italian Curency: Ç -Ç 12.345,78
Locale: 00001404 Norwegian (Bokmsl) Curency: kr kr
-12á345,78
C:\TEST>