C Function Localeconv
Title: C Library Function β localeconv() | Rookie Tutorial\n\n[ C Standard Library - ](#)\n\n## Description\n\n`localeconv()` is a function in the C standard library `` used to obtain number and currency formatting information related to the current locale setting. It returns a pointer to a `struct lconv` structure, which contains localization formatting information under the current locale setting.\n\n## Declaration\n\nThe following is the declaration for the localeconv() function.\n\n#include struct lconv *localeconv(void);\n## Parameters\n\n* **NA**\n\n### Return Value\n\n* Returns a pointer to a `struct lconv` structure, which contains localization information under the current locale setting.\n\nThe structure of the pointer to the current locale **struct lconv** is as follows:\n\nstruct lconv { char *decimal_point; // Decimal point character char *thousands_sep; // Thousands separator char *grouping; // Number grouping method char *int_curr_symbol; // International currency symbol char *currency_symbol; // Local currency symbol char *mon_decimal_point; // Monetary decimal point character char *mon_thousands_sep; // Monetary thousands separator char *mon_grouping; // Monetary grouping method char *positive_sign; // Positive sign char *negative_sign; // Negative sign char int_frac_digits; // International fractional digits char frac_digits; // Local fractional digits char p_cs_precedes; // Positive currency symbol precedes char p_sep_by_space; // Space between positive currency symbol and value char n_cs_precedes; // Negative currency symbol precedes char n_sep_by_space; // Space between negative currency symbol and value char p_sign_posn; // Positive sign position char n_sign_posn; // Negative sign position};\n## Example\n\nThe following is an example code that uses localeconv to get and print the number and currency formatting information for the current locale setting:\n\n## Example\n\n#include \n\n#include \n\nint main(){\n\n// Set the locale information to the default setting from the user environment variable\n\nsetlocale(LC_ALL,"");\n\n// Get the localization information for the current locale setting\n\nstruct lconv *lc =localeconv();\n\n// Print number formatting information\n\nprintf("Decimal point character: %sn", lc->decimal_point);\n\nprintf("Thousands separator: %sn", lc->thousands_sep);\n\nprintf("Grouping: %sn", lc->grouping);\n\n// Print currency formatting information\n\nprintf("International currency symbol: %sn", lc->int_curr_symbol);\n\nprintf("Local currency symbol: %sn", lc->currency_symbol);\n\nprintf("Monetary decimal point character: %sn", lc->mon_decimal_point);\n\nprintf("Monetary thousands separator: %sn", lc->mon_thousands_sep);\n\nprintf("Monetary grouping: %sn", lc->mon_grouping);\n\nprintf("Positive sign: %sn", lc->positive_sign);\n\nprintf("Negative sign: %sn", lc->negative_sign);\n\nprintf("International fractional digits: %dn", lc->int_frac_digits);\n\nprintf("Local fractional digits: %dn", lc->frac_digits);\n\nprintf("Positive currency symbol precedes: %dn", lc->p_cs_precedes);\n\nprintf("Positive currency symbol separated by space: %dn", lc->p_sep_by_space);\n\nprintf("Negative currency symbol precedes: %dn", lc->n_cs_precedes);\n\nprintf("Negative currency symbol separated by space: %dn", lc->n_sep_by_space);\n\nprintf("Positive sign position: %dn", lc->p_sign_posn);\n\nprintf("Negative sign position: %dn", lc->n_sign_posn);\n\nreturn 0;\n\n}\n\nLet's compile and run the above program, which will produce the following result:\n\nDecimal point character: .Thousands separator: ,Grouping: International currency symbol: CNY Local currency symbol: οΏ₯Monetary decimal point character: .Monetary thousands separator: ,Monetary grouping: Positive sign: Negative sign: -International fractional digits: 2Local fractional digits: 2Positive currency symbol precedes: 1Positive currency symbol separated by space: 0Negative currency symbol precedes: 1Negative currency symbol separated by space: 0Positive sign position: 1Negative sign position:Discussion\n### Code Analysis\n\n* **Number formatting information**:\n\n * `decimal_point`: Decimal point character, e.g., "`.`".\n * `thousands_sep`: Thousands separator, e.g., "`,`".\n * `grouping`: Number grouping method.\n\n* **Currency formatting information**:\n\n * `int_curr_symbol`: International currency symbol, e.g., "USD".\n * `currency_symbol`: Local currency symbol, e.g., "$".\n * `mon_decimal_point`: Monetary decimal point character.\n * `mon_thousands_sep`: Monetary thousands separator.\n * `mon_grouping`: Monetary grouping method.\n * `positive_sign`: Positive sign, e.g., "".\n * `negative_sign`: Negative sign, e.g., "-".\n * `int_frac_digits`: International fractional digits.\n * `frac_digits`: Local fractional digits.\n * `p_cs_precedes`: Positive currency symbol precedes (1 means precedes, 0 means follows).\n * `p_sep_by_space`: Space between positive currency symbol and value (1 means space present, 0 means no space).\n * `n_cs_precedes`: Negative currency symbol precedes (1 means precedes, 0 means follows).\n * `n_sep_by_space`: Space between negative currency symbol and value (1 means space present, 0 means no space).\n * `p_sign_posn`: Positive sign position (1 means precedes, 2 means follows, 3 means near the value, 4 means near the currency symbol).\n * `n_sign_posn`: Negative sign position (1 means precedes, 2 means follows, 3 means near the value, 4 means near the currency symbol).\n\n### Summary\n\nThe `localeconv` function allows a program to obtain the number and currency formatting information for the current locale setting. This is very useful for writing internationalized programs that need to handle multiple languages and currency formats. By using the `setlocale` and `localeconv` functions, programmers can implement localization of their programs, thereby meeting the needs of different user groups.\n\n[ C Standard Library - ](#)
YouTip