| |||
Home > The C and C++ Libraries > Tailoring locale and CTYPE > _get_lc_numeric() |
_get_lc_numeric()
must return a pointer
to an __lc_numeric_blk structure. Use the macros
in Example 4.7 to create
the structure.
Example 4.7. LC_NUMERIC_DEF
__LC_NUMERIC_DEF(lcnumeric_c, "C",".","","") __LC_NUMERIC_DEF(lcnumeric_iso8859_1, "ISO8859-1", ".", ",", "\3") __LC_NUMERIC_DEF(lcnumeric_fr, "fr", ",", ".", "\3") __LC_INDEX_END(lcnumeric_dummy) void const *_get_lc_numeric(void const *null, char const *name) { return _findlocale(&lcnumeric_c_index, name); } void test_lc_numeric(void) { double pi = 4*atan(1.); char buf[20]; /* Test changing decimal point as we shift in and out of French * numeric locale. */ EQS(setlocale(LC_NUMERIC, NULL), "C"); /* verify starting point */ snprintf(buf, sizeof(buf), "%g", pi); EQS(buf, "3.14159"); EQI(!setlocale(LC_NUMERIC, "ISO8859-1"), 0); /* setlocale should work */ EQS(setlocale(LC_NUMERIC, NULL), "ISO8859-1"); snprintf(buf, sizeof(buf), "%g", pi); EQS(buf, "3.14159"); EQI(!setlocale(LC_NUMERIC, "fr"), 0); /* setlocale should work */ EQS(setlocale(LC_NUMERIC, NULL), "fr"); snprintf(buf, sizeof(buf), "%g", pi); EQS(buf, "3,14159"); EQI(!setlocale(LC_NUMERIC, "C"), 0); /* setlocale should work */ EQS(setlocale(LC_NUMERIC, NULL), "C"); snprintf(buf, sizeof(buf), "%g", pi); EQS(buf, "3.14159"); }
The offset fields are interpreted similarly to __lc_monetary_blk
.