Читаем Linux программирование в примерах полностью

Корректное форматирование числовых и денежных значений требует значительной низкоуровневой информации. Указанная информация доступна в struct lconv, которую получают с помощью функции localeconv():

#include /* ISO С */

struct lconv *localeconv(void);

Подобно функции ctime(), эта функция возвращает указатель на внутренние статические данные. Следует сделать копию возвращенных данных, поскольку последующие вызовы могут возвратить другие значения, если локаль изменилась. Вот struct lconv (слегка сжатая), непосредственно из GLIBC :

struct lconv {

 /* Числовая (не денежная) информация. */

 char *decimal_point; /* Разделитель десятичной дроби. */

 char *thousands_sep; /* Разделитель тысяч. */

 /* Каждый элемент является числом цифр в каждой группе;

    элементы с большими индексами оставлены дальше. Элемент со

    значением CHAR_MAX означает, что дальнейшая группировка не

    производится. Элемент со значением 0 означает, что предыдущий

    элемент используется для всех оставшихся групп. */

 char *grouping;

 /* Денежная информация. */

 /* Первые три символа являются символами валют из ISO 4217.

    Четвертый символ является разделителем. Пятый символ '\0'. */

 char *int_curr_symbol;

 char *currency_symbol; /* Символ местной валюты. */

 char *mon_decimal_point; /* Символ десятичной точки. */

 char *mon_thousands_sep; /* Разделитель тысяч. */

 char *mon_grouping; /* Аналогично элементу 'группировки' (выше). */

 char *positive_sign; /* Знак для положительных значений. */

 char *negative_sign; /* Знак для отрицательных значений. */

 char int_frac_digits; /* Международные цифры дробей. */

 char frac_digits; /* Местные цифры дробей. */

 /* 1, если символ валюты перед положит, значением, 0, если после. */

 char p_cs_precedes;

 /* 1, если символ валюты отделяется от положит, значения пробелом. */

 char p_sep_by_space;

 /* 1, если символ валюты перед отриц. значением, 0, если после. */

 char n_cs_precedes;

 /* 1, если символ валюты отделяется от отриц. значения пробелом. */

 char n_sep_by_space;

 /* Размещение положительного и отрицательного знака:

    0 Количество и символ валюты окружены скобками.

    1 Строка знака перед количеством и символом валюты.

    2 Строка знака за количеством и символом валюты.

    3 Строка знака непосредственно перед символом валюты.

    4 Строка знака непосредственно после символа валюты. */

 char p_sign_posn;

 char n_sign_posn;

 /* 1, если int_curr_symbol до положит. значения, 0, если после. */

 char int_p_cs_precedes;

 /* 1, если int_curr_symbol отделен от положит, знач. пробелом. */

 char int_p_sep_by_space;

 /* 1, если int_curr_symbol перед отриц. значением, 0, если после. */

 char int_n_cs_precedes;

 /* 1, если int_curr_symbol отделен от отриц. знач. пробелом. */

 char int_n_sep_by_space;

 /* Размещение положительного и отрицательного знака:

Перейти на страницу:

Похожие книги

C++ Primer Plus
C++ Primer Plus

C++ Primer Plus is a carefully crafted, complete tutorial on one of the most significant and widely used programming languages today. An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages.The sixth edition of C++ Primer Plus has been updated and expanded to cover the latest developments in C++, including a detailed look at the new C++11 standard.Author and educator Stephen Prata has created an introduction to C++ that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C++ language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.In C++ Primer Plus, you'll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:• A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard• Complete, integrated discussion of both basic C language and additional C++ features• Clear guidance about when and why to use a feature• Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time• Hundreds of practical sample programs• Review questions and programming exercises at the end of each chapter to test your understanding• Coverage of generic C++ gives you the greatest possible flexibility• Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces

Стивен Прата

Программирование, программы, базы данных