2.8.7. _get_lc_numeric()

_get_lc_numeric() 必须返回一个指向 __lc_numeric_blk 结构的指针。 可以使用Example 2.14 中的宏来创建该结构。

Example 2.14. 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);

    EQS(setlocale(LC_NUMERIC, NULL), "ISO8859-1");	

    snprintf(buf, sizeof(buf), "%g", pi); EQS(buf, "3.14159");	

    EQI(!setlocale(LC_NUMERIC, "fr"), 0);

    EQS(setlocale(LC_NUMERIC, NULL), "fr");	

    snprintf(buf, sizeof(buf), "%g", pi); EQS(buf, "3,14159");	

    EQI(!setlocale(LC_NUMERIC, "C"), 0);

    EQS(setlocale(LC_NUMERIC, NULL), "C");	

    snprintf(buf, sizeof(buf), "%g", pi); EQS(buf, "3.14159");	

}

偏移字段的解释与 __lc_monetary_blk 类似。

Copyright © 2007 ARM Limited. All rights reserved. ARM DUI 0349AC
Non-Confidential